Search in sources :

Example 1 with ViewHolderBase

use of com.github.obsessive.library.adapter.ViewHolderBase in project SimplifyReader by chentao0707.

the class CommonImagePickerDetailActivity method initViewsAndEvents.

@Override
protected void initViewsAndEvents() {
    mGridViewAdapter = new ListViewDataAdapter<>(new ViewHolderCreator<ImageItem>() {

        @Override
        public ViewHolderBase<ImageItem> createViewHolder(int position) {
            return new ViewHolderBase<ImageItem>() {

                ImageView mItemImage;

                @Override
                public View createView(LayoutInflater layoutInflater) {
                    View convertView = layoutInflater.inflate(R.layout.grid_item_common_image_picker, null);
                    mItemImage = ButterKnife.findById(convertView, R.id.grid_item_common_image_picker_image);
                    return convertView;
                }

                @Override
                public void showData(int position, ImageItem itemData) {
                    if (null != itemData) {
                        String imagePath = itemData.getImagePath();
                        if (!CommonUtils.isEmpty(imagePath)) {
                            ImageLoader.getInstance().displayImage("file://" + imagePath, mItemImage, ImageLoaderHelper.getInstance(mContext).getDisplayOptions());
                        }
                    }
                }
            };
        }
    });
    mGridViewAdapter.getDataList().addAll(mGridListData);
    commonImagePickerDetailGridView.setAdapter(mGridViewAdapter);
    commonImagePickerDetailGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (null != mGridViewAdapter && null != mGridViewAdapter.getDataList() && !mGridViewAdapter.getDataList().isEmpty() && position < mGridViewAdapter.getDataList().size()) {
                Intent intent = new Intent();
                intent.putExtra(KEY_BUNDLE_RESULT_IMAGE_PATH, mGridViewAdapter.getDataList().get(position).getImagePath());
                setResult(RESULT_OK, intent);
                finish();
            }
        }
    });
}
Also used : ViewHolderBase(com.github.obsessive.library.adapter.ViewHolderBase) Intent(android.content.Intent) GridView(android.widget.GridView) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) LayoutInflater(android.view.LayoutInflater) AdapterView(android.widget.AdapterView) ImageItem(com.github.obsessive.library.picker.ImageItem) ImageView(android.widget.ImageView) ViewHolderCreator(com.github.obsessive.library.adapter.ViewHolderCreator)

Example 2 with ViewHolderBase

use of com.github.obsessive.library.adapter.ViewHolderBase in project SimplifyReader by chentao0707.

the class CommonImagePickerListActivity method initViewsAndEvents.

@Override
protected void initViewsAndEvents() {
    setTitle(getResources().getString(R.string.title_image_picker));
    mListViewAdapter = new ListViewDataAdapter<ImageBucket>(new ViewHolderCreator<ImageBucket>() {

        @Override
        public ViewHolderBase<ImageBucket> createViewHolder(int position) {
            return new ViewHolderBase<ImageBucket>() {

                ImageView mItemImage;

                TextView mItemTitle;

                @Override
                public View createView(LayoutInflater layoutInflater) {
                    View convertView = layoutInflater.inflate(R.layout.list_item_common_image_picker, null);
                    mItemImage = ButterKnife.findById(convertView, R.id.list_item_common_image_picker_thumbnail);
                    mItemTitle = ButterKnife.findById(convertView, R.id.list_item_common_image_picker_title);
                    return convertView;
                }

                @Override
                public void showData(int position, ImageBucket itemData) {
                    if (null != itemData) {
                        String imagePath = itemData.bucketList.get(0).getImagePath();
                        if (!CommonUtils.isEmpty(imagePath)) {
                            ImageLoader.getInstance().displayImage("file://" + imagePath, mItemImage, ImageLoaderHelper.getInstance(mContext).getDisplayOptions());
                        }
                        int count = itemData.count;
                        String title = itemData.bucketName;
                        if (!CommonUtils.isEmpty(title)) {
                            mItemTitle.setText(title + "(" + count + ")");
                        }
                    }
                }
            };
        }
    });
    mImagePickerListView.setAdapter(mListViewAdapter);
    mImagePickerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (null != mListViewAdapter && null != mListViewAdapter.getDataList() && !mListViewAdapter.getDataList().isEmpty() && position < mListViewAdapter.getDataList().size()) {
                Bundle extras = new Bundle();
                extras.putParcelableArrayList(KEY_BUNDLE_ALBUM_PATH, mListViewAdapter.getDataList().get(position).bucketList);
                extras.putString(KEY_BUNDLE_ALBUM_NAME, mListViewAdapter.getDataList().get(position).bucketName);
                readyGoForResult(CommonImagePickerDetailActivity.class, IMAGE_PICKER_DETAIL_REQUEST_CODE, extras);
            }
        }
    });
    mAlbumLoadTask = new AsyncTask<Void, Void, List<ImageBucket>>() {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            toggleShowLoading(true, null);
            ImagePickerHelper.getHelper().init(mContext);
        }

        @Override
        protected List<ImageBucket> doInBackground(Void... params) {
            return ImagePickerHelper.getHelper().getImagesBucketList();
        }

        @Override
        protected void onPostExecute(List<ImageBucket> list) {
            toggleShowLoading(false, null);
            mListViewAdapter.getDataList().addAll(list);
            mListViewAdapter.notifyDataSetChanged();
        }
    };
    mAlbumLoadTask.execute();
}
Also used : ViewHolderBase(com.github.obsessive.library.adapter.ViewHolderBase) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ImageBucket(com.github.obsessive.library.picker.ImageBucket) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) List(java.util.List) ImageView(android.widget.ImageView) ViewHolderCreator(com.github.obsessive.library.adapter.ViewHolderCreator)

Example 3 with ViewHolderBase

use of com.github.obsessive.library.adapter.ViewHolderBase in project SimplifyReader by chentao0707.

the class HomeActivity method initializeViews.

@Override
public void initializeViews(List<BaseLazyFragment> fragments, List<NavigationEntity> navigationList) {
    mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open, R.string.drawer_close) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            setTitle(getString(R.string.app_name));
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (null != mNavListAdapter) {
                setTitle(mNavListAdapter.getItem(mCurrentMenuCheckedPos).getName());
            }
        }
    };
    mActionBarDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
    if (null != fragments && !fragments.isEmpty()) {
        mViewPager.setEnableScroll(false);
        mViewPager.setOffscreenPageLimit(fragments.size());
        mViewPager.setAdapter(new VPFragmentAdapter(getSupportFragmentManager(), fragments));
    }
    mNavListAdapter = new ListViewDataAdapter<NavigationEntity>(new ViewHolderCreator<NavigationEntity>() {

        @Override
        public ViewHolderBase<NavigationEntity> createViewHolder(int position) {
            return new ViewHolderBase<NavigationEntity>() {

                ImageView itemIcon;

                TextView itemName;

                @Override
                public View createView(LayoutInflater layoutInflater) {
                    View convertView = layoutInflater.inflate(R.layout.list_item_navigation, null);
                    itemIcon = ButterKnife.findById(convertView, R.id.list_item_navigation_icon);
                    itemName = ButterKnife.findById(convertView, R.id.list_item_navigation_name);
                    return convertView;
                }

                @Override
                public void showData(int i, NavigationEntity navigationEntity) {
                    itemIcon.setImageResource(navigationEntity.getIconResId());
                    itemName.setText(navigationEntity.getName());
                    if (mCurrentMenuCheckedPos == i) {
                        // checked
                        itemName.setTextColor(getResources().getColor(mCheckedListItemColorResIds[i]));
                    } else {
                        // unchecked
                        itemName.setTextColor(getResources().getColor(android.R.color.black));
                    }
                }
            };
        }
    });
    mNavListView.setAdapter(mNavListAdapter);
    mNavListAdapter.getDataList().addAll(navigationList);
    mNavListAdapter.notifyDataSetChanged();
    setTitle(mNavListAdapter.getItem(mCurrentMenuCheckedPos).getName());
    mNavListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mCurrentMenuCheckedPos = position;
            mNavListAdapter.notifyDataSetChanged();
            mDrawerLayout.closeDrawer(Gravity.LEFT);
            mViewPager.setCurrentItem(mCurrentMenuCheckedPos, false);
        }
    });
}
Also used : ViewHolderBase(com.github.obsessive.library.adapter.ViewHolderBase) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) HomeView(com.github.obsessive.simplifyreader.view.HomeView) TextView(android.widget.TextView) ListView(android.widget.ListView) NavigationEntity(com.github.obsessive.simplifyreader.bean.NavigationEntity) VPFragmentAdapter(com.github.obsessive.simplifyreader.ui.adpter.VPFragmentAdapter) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) ViewHolderCreator(com.github.obsessive.library.adapter.ViewHolderCreator)

Example 4 with ViewHolderBase

use of com.github.obsessive.library.adapter.ViewHolderBase in project SimplifyReader by chentao0707.

the class AboutUsActivity method initViewsAndEvents.

@Override
protected void initViewsAndEvents() {
    mAboutArray = getResources().getStringArray(R.array.about_list);
    mListViewDataAdapter = new ListViewDataAdapter<>(new ViewHolderCreator<AboutListEntity>() {

        @Override
        public ViewHolderBase<AboutListEntity> createViewHolder(int position) {
            return new ViewHolderBase<AboutListEntity>() {

                TextView mTitle;

                TextView mSubTitle;

                @Override
                public View createView(LayoutInflater layoutInflater) {
                    View convertView = layoutInflater.inflate(R.layout.list_item_about, null);
                    mTitle = ButterKnife.findById(convertView, R.id.list_item_about_title);
                    mSubTitle = ButterKnife.findById(convertView, R.id.list_item_about_sub_title);
                    return convertView;
                }

                @Override
                public void showData(int position, AboutListEntity itemData) {
                    if (null != itemData) {
                        if (!CommonUtils.isEmpty(itemData.getTitle())) {
                            mTitle.setText(itemData.getTitle());
                        }
                        if (!CommonUtils.isEmpty(itemData.getSubTitle())) {
                            mSubTitle.setText(itemData.getSubTitle());
                        }
                    }
                }
            };
        }
    });
    mListView.setAdapter(mListViewDataAdapter);
    mItemData = new AboutListEntity();
    mItemData.setTitle(mAboutArray[0]);
    try {
        PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
        String version = String.format(getResources().getString(R.string.splash_version), packageInfo.versionName);
        if (!CommonUtils.isEmpty(version)) {
            mItemData.setSubTitle(version);
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    mListViewDataAdapter.getDataList().add(mItemData);
    mItemData = new AboutListEntity();
    mItemData.setTitle(mAboutArray[1]);
    mItemData.setSubTitle("https://github.com/SkillCollege");
    mListViewDataAdapter.getDataList().add(mItemData);
    mItemData = new AboutListEntity();
    mItemData.setTitle(mAboutArray[2]);
    mItemData.setSubTitle("https://github.com/SkillCollege/SimplifyReader");
    mListViewDataAdapter.getDataList().add(mItemData);
    mItemData = new AboutListEntity();
    mItemData.setTitle(mAboutArray[3]);
    mListViewDataAdapter.getDataList().add(mItemData);
    mItemData = new AboutListEntity();
    mItemData.setTitle(mAboutArray[4]);
    mListViewDataAdapter.getDataList().add(mItemData);
    mListViewDataAdapter.notifyDataSetChanged();
    mPayCode.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            DecodeUtils decodeUtils = new DecodeUtils(DecodeUtils.DECODE_DATA_MODE_ALL);
            String url = decodeUtils.decodeWithZxing(BitmapFactory.decodeResource(getResources(), R.drawable.pay_qrcode));
            if (!CommonUtils.isEmpty(url)) {
                TLog.d(TAG_LOG, url);
                intent.setData(Uri.parse(url));
            }
            startActivity(intent);
        }
    });
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Bundle extras = new Bundle();
            switch(position) {
                case 0:
                    // version
                    break;
                case 1:
                    // author
                    extras.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mAboutArray[1]);
                    extras.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, true);
                    extras.putString(BaseWebActivity.BUNDLE_KEY_URL, "https://github.com/SkillCollege");
                    readyGo(BaseWebActivity.class, extras);
                    break;
                case 2:
                    // project index
                    extras.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mAboutArray[2]);
                    extras.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, true);
                    extras.putString(BaseWebActivity.BUNDLE_KEY_URL, "https://github.com/SkillCollege/SimplifyReader");
                    readyGo(BaseWebActivity.class, extras);
                    break;
                case 3:
                    // project description
                    extras.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mAboutArray[3]);
                    extras.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                    extras.putString(BaseWebActivity.BUNDLE_KEY_URL, "file:///android_asset/project_description.html");
                    readyGo(BaseWebActivity.class, extras);
                    break;
                case 4:
                    // open source description
                    extras.putString(BaseWebActivity.BUNDLE_KEY_TITLE, mAboutArray[4]);
                    extras.putBoolean(BaseWebActivity.BUNDLE_KEY_SHOW_BOTTOM_BAR, false);
                    extras.putString(BaseWebActivity.BUNDLE_KEY_URL, "file:///android_asset/open_source.html");
                    readyGo(BaseWebActivity.class, extras);
                    break;
            }
        }
    });
}
Also used : ViewHolderBase(com.github.obsessive.library.adapter.ViewHolderBase) PackageInfo(android.content.pm.PackageInfo) Bundle(android.os.Bundle) Intent(android.content.Intent) BaseWebActivity(com.github.obsessive.library.base.BaseWebActivity) ImageView(android.widget.ImageView) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AboutListEntity(com.github.obsessive.simplifyreader.bean.AboutListEntity) PackageManager(android.content.pm.PackageManager) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ViewHolderCreator(com.github.obsessive.library.adapter.ViewHolderCreator) DecodeUtils(com.github.obsessive.simplifyreader.ui.activity.qrcode.decode.DecodeUtils)

Example 5 with ViewHolderBase

use of com.github.obsessive.library.adapter.ViewHolderBase in project SimplifyReader by chentao0707.

the class ImagesListFragment method initViewsAndEvents.

@Override
protected void initViewsAndEvents() {
    mListViewAdapter = new ListViewDataAdapter<ImagesListEntity>(new ViewHolderCreator<ImagesListEntity>() {

        @Override
        public ViewHolderBase<ImagesListEntity> createViewHolder(int position) {
            return new ViewHolderBase<ImagesListEntity>() {

                PLAImageView mItemImage;

                @Override
                public View createView(LayoutInflater layoutInflater) {
                    View convertView = layoutInflater.inflate(R.layout.list_item_images_list, null);
                    mItemImage = ButterKnife.findById(convertView, R.id.list_item_images_list_image);
                    return convertView;
                }

                @Override
                public void showData(int position, ImagesListEntity itemData) {
                    int width = itemData.getThumbnailWidth();
                    int height = itemData.getThumbnailHeight();
                    String imageUrl = itemData.getThumbnailUrl();
                    if (!CommonUtils.isEmpty(imageUrl)) {
                        ImageLoader.getInstance().displayImage(imageUrl, mItemImage);
                    }
                    mItemImage.setImageWidth(width);
                    mItemImage.setImageHeight(height);
                }
            };
        }
    });
    mListView.setOnItemClickListener(this);
    mListView.setOnLoadMoreListener(this);
    mListView.setAdapter(mListViewAdapter);
    mSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.gplus_color_1), getResources().getColor(R.color.gplus_color_2), getResources().getColor(R.color.gplus_color_3), getResources().getColor(R.color.gplus_color_4));
    mSwipeRefreshLayout.setOnRefreshListener(this);
}
Also used : PLAImageView(com.github.obsessive.library.pla.PLAImageView) ViewHolderBase(com.github.obsessive.library.adapter.ViewHolderBase) LayoutInflater(android.view.LayoutInflater) ResponseImagesListEntity(com.github.obsessive.simplifyreader.bean.ResponseImagesListEntity) ImagesListEntity(com.github.obsessive.simplifyreader.bean.ImagesListEntity) ViewHolderCreator(com.github.obsessive.library.adapter.ViewHolderCreator) ImagesListView(com.github.obsessive.simplifyreader.view.ImagesListView) InjectView(butterknife.InjectView) PLAImageView(com.github.obsessive.library.pla.PLAImageView) View(android.view.View) PLALoadMoreListView(com.github.obsessive.simplifyreader.widgets.PLALoadMoreListView) PLAAdapterView(com.github.obsessive.library.pla.PLAAdapterView)

Aggregations

LayoutInflater (android.view.LayoutInflater)6 View (android.view.View)6 InjectView (butterknife.InjectView)6 ViewHolderBase (com.github.obsessive.library.adapter.ViewHolderBase)6 ViewHolderCreator (com.github.obsessive.library.adapter.ViewHolderCreator)6 ImageView (android.widget.ImageView)5 AdapterView (android.widget.AdapterView)4 TextView (android.widget.TextView)4 ListView (android.widget.ListView)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 GridView (android.widget.GridView)1 ImageButton (android.widget.ImageButton)1 MultiItemRowListAdapter (com.github.obsessive.library.adapter.MultiItemRowListAdapter)1 BaseWebActivity (com.github.obsessive.library.base.BaseWebActivity)1 ImageBucket (com.github.obsessive.library.picker.ImageBucket)1 ImageItem (com.github.obsessive.library.picker.ImageItem)1