Search in sources :

Example 1 with CircleTransform

use of com.group1.swepproject.user.nochange.DataBaseForTheDebtorsAndCreditors.Utils.CircleTransform in project noChange by Khalidtoak.

the class Adapters method onBindViewHolder.

@Override
public void onBindViewHolder(final AdapterViewHolder holder, int position) {
    // here the views are binded to the view holder
    // we move our cursor to the position on the recycler view adapter
    mCursor.moveToPosition(position);
    // get the values in our table that we have queried
    // by calling get column Index
    // and passing the column name
    final String customerName = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_CUSTOMER_NAME));
    String boughtStuff = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_ITEM_BOUGHT));
    String howMuch = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_HOW_MUCH));
    String Time = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_TIME_STAMP));
    String DebtOrChange = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_DEBT_OR_CHANGE));
    final String phoneNo = mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_PHONE_NUMBER));
    // display this data on our recyclerview
    holder.CustomerName.setText(customerName);
    holder.ItemBought.setText("bought Item: " + boughtStuff);
    holder.amount.setText(howMuch + "Naira");
    holder.time.setText(Time);
    holder.itemView.setTag(mCursor.getLong(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase._ID)));
    // for the Image ..we made use of glide Image loading library and using the Circle transform class created
    // in the utils package... we display the circuilar version of the image
    Glide.with(context).load(mCursor.getString(mCursor.getColumnIndex(CreditorsAndDebtorsDataBase.COLUMN_IMAGE))).transform(new CircleTransform(context)).crossFade().into(holder.imageProfile);
    // an image button is a clickable image
    // we create a pop up menu and set a listener for it so that we click it...
    // we will bw able to perform a certain action
    holder.callOrTextessage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            PopupMenu popupMenu = new PopupMenu(context, holder.callOrTextessage);
            // we always inflate menus in android or else the menu won't show
            // A menu resource defines an application menu
            // (Options Menu, Context Menu, or submenu) that can be inflated with MenuInflater
            popupMenu.inflate(R.menu.menu);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                popupMenu.setGravity(Gravity.CENTER);
            }
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    // get the id of the item that was clicked in the menu
                    switch(menuItem.getItemId()) {
                        // if call is clicked
                        case R.id.call:
                            // open the dialer using an implicit intent
                            /**
                             * An intent is an abstract description of an operation to be performed.
                             * It can be used with startActivity to launch an Activity,
                             * broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent)
                             * or bindService(Intent, ServiceConnection, int) to communicate with a Background Service.
                             * Explicit intent launches an intent in your app while implicit intents launches another app
                             * from your app
                             * here we are launching the dialer app from our app *
                             */
                            openDialer(phoneNo);
                            break;
                        case R.id.send_text_message:
                            // here we will launch the sms app from our app
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + phoneNo));
                            context.startActivity(intent);
                            break;
                    }
                    return false;
                }
            });
            // show the popup menu
            popupMenu.show();
        }
    });
}
Also used : CircleTransform(com.group1.swepproject.user.nochange.DataBaseForTheDebtorsAndCreditors.Utils.CircleTransform) MenuItem(android.view.MenuItem) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) PopupMenu(android.widget.PopupMenu)

Aggregations

Intent (android.content.Intent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 PopupMenu (android.widget.PopupMenu)1 TextView (android.widget.TextView)1 CircleTransform (com.group1.swepproject.user.nochange.DataBaseForTheDebtorsAndCreditors.Utils.CircleTransform)1