Search in sources :

Example 56 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project SwipeRecyclerView by yanzhenjie.

the class ListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scroll);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    mRecyclerView = findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
    mRecyclerView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(View itemView, int position) {
            // 根据原position判断该item是否是parent item
            if (mAdapter.isParentItem(position)) {
                // 换取parent position
                final int parentPosition = mAdapter.parentItemPosition(position);
                // 判断parent是否打开了二级菜单
                if (mAdapter.isExpanded(parentPosition)) {
                    mDataList.get(parentPosition).setExpanded(false);
                    mAdapter.notifyParentChanged(parentPosition);
                    // 关闭该parent下的二级菜单
                    mAdapter.collapseParent(parentPosition);
                } else {
                    mDataList.get(parentPosition).setExpanded(true);
                    mAdapter.notifyParentChanged(parentPosition);
                    // 打开该parent下的二级菜单
                    mAdapter.expandParent(parentPosition);
                }
            } else {
                // 换取parent position
                int parentPosition = mAdapter.parentItemPosition(position);
                // 换取child position
                int childPosition = mAdapter.childItemPosition(position);
                String message = String.format("我是%1$d爸爸的%2$d儿子", parentPosition, childPosition);
                Toast.makeText(ListActivity.this, message, Toast.LENGTH_LONG).show();
            }
        }
    });
    mAdapter = new ExpandedAdapter(this);
    mRecyclerView.setAdapter(mAdapter);
    refresh();
}
Also used : DefaultItemDecoration(com.yanzhenjie.recyclerview.widget.DefaultItemDecoration) OnItemClickListener(com.yanzhenjie.recyclerview.OnItemClickListener) ExpandedAdapter(com.yanzhenjie.recyclerview.sample.adapter.ExpandedAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) View(android.view.View) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 57 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project epoxy by airbnb.

the class Carousel method setInitialPrefetchItemCount.

/**
 * If you are using a Linear or Grid layout manager you can use this to set the item prefetch
 * count. Only use this if you are not using {@link #setNumViewsToShowOnScreen(float)}
 *
 * @see #setNumViewsToShowOnScreen(float)
 * @see LinearLayoutManager#setInitialPrefetchItemCount(int)
 */
@ModelProp(group = "prefetch")
public void setInitialPrefetchItemCount(int numItemsToPrefetch) {
    if (numItemsToPrefetch < 0) {
        throw new IllegalStateException("numItemsToPrefetch must be greater than 0");
    }
    // Use the linearlayoutmanager default of 2 if the user did not specify one
    int prefetchCount = numItemsToPrefetch == 0 ? 2 : numItemsToPrefetch;
    LayoutManager layoutManager = getLayoutManager();
    if (layoutManager instanceof LinearLayoutManager) {
        ((LinearLayoutManager) layoutManager).setInitialPrefetchItemCount(prefetchCount);
    }
}
Also used : LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 58 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project xabber-android by redsolution.

the class ServerInfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_server_info);
    final Intent intent = getIntent();
    AccountJid account = getAccount(intent);
    if (account == null) {
        finish();
        return;
    }
    accountItem = AccountManager.getInstance().getAccount(account);
    if (accountItem == null) {
        Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT);
        finish();
        return;
    }
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    toolbar.setTitle(accountItem.getConnection().getXMPPServiceDomain());
    BarPainter barPainter = new BarPainter(this, toolbar);
    barPainter.updateWithAccountName(account);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.server_info_recycler_view);
    serverInfoAdapter = new ServerInfoAdapter();
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(serverInfoAdapter);
    progressBar = findViewById(R.id.server_info_progress_bar);
    requestServerInfo();
}
Also used : ServerInfoAdapter(com.xabber.android.ui.adapter.ServerInfoAdapter) AccountJid(com.xabber.android.data.entity.AccountJid) Intent(android.content.Intent) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Toolbar(androidx.appcompat.widget.Toolbar) BarPainter(com.xabber.android.ui.color.BarPainter)

Example 59 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project xabber-android by redsolution.

the class MessageVH method setupForwarded.

protected void setupForwarded(MessageItem messageItem, MessagesAdapter.MessageExtraData extraData) {
    String[] forwardedIDs = messageItem.getForwardedIdsAsArray();
    if (!Arrays.asList(forwardedIDs).contains(null)) {
        RealmResults<MessageItem> forwardedMessages = MessageDatabaseManager.getInstance().getRealmUiThread().where(MessageItem.class).in(MessageItem.Fields.UNIQUE_ID, forwardedIDs).findAllSorted(MessageItem.Fields.TIMESTAMP, Sort.ASCENDING);
        if (forwardedMessages.size() > 0) {
            RecyclerView recyclerView = forwardLayout.findViewById(R.id.recyclerView);
            ForwardedAdapter adapter = new ForwardedAdapter(forwardedMessages, extraData);
            recyclerView.setLayoutManager(new LinearLayoutManager(extraData.getContext()));
            recyclerView.setAdapter(adapter);
            forwardLayout.setBackgroundColor(ColorManager.getColorWithAlpha(R.color.forwarded_background_color, 0.2f));
            forwardLeftBorder.setBackgroundColor(extraData.getAccountMainColor());
            forwardLayout.setVisibility(View.VISIBLE);
        }
    }
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 60 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project xabber-android by redsolution.

the class FileMessageVH method setUpFile.

private void setUpFile(RealmList<Attachment> attachments, Context context) {
    RealmList<Attachment> fileAttachments = new RealmList<>();
    for (Attachment attachment : attachments) {
        if (!attachment.isImage())
            fileAttachments.add(attachment);
    }
    if (fileAttachments.size() > 0) {
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
        rvFileList.setLayoutManager(layoutManager);
        FilesAdapter adapter = new FilesAdapter(fileAttachments, this);
        rvFileList.setAdapter(adapter);
        fileLayout.setVisibility(View.VISIBLE);
    }
}
Also used : FilesAdapter(com.xabber.android.ui.adapter.FilesAdapter) RealmList(io.realm.RealmList) Attachment(com.xabber.android.data.database.messagerealm.Attachment) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)470 RecyclerView (androidx.recyclerview.widget.RecyclerView)281 View (android.view.View)183 TextView (android.widget.TextView)65 ArrayList (java.util.ArrayList)37 Nullable (androidx.annotation.Nullable)33 Bundle (android.os.Bundle)32 Toolbar (androidx.appcompat.widget.Toolbar)32 Intent (android.content.Intent)30 ImageView (android.widget.ImageView)27 List (java.util.List)24 Test (org.junit.Test)24 Context (android.content.Context)23 NonNull (androidx.annotation.NonNull)23 ViewGroup (android.view.ViewGroup)22 AlertDialog (androidx.appcompat.app.AlertDialog)21 ContextualCard (com.android.settings.homepage.contextualcards.ContextualCard)20 LayoutInflater (android.view.LayoutInflater)18 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)16 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)16