Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用FirestorePagingAdapter时手动插入项目_Android_Firebase_Google Cloud Firestore_Firebaseui - Fatal编程技术网

Android 使用FirestorePagingAdapter时手动插入项目

Android 使用FirestorePagingAdapter时手动插入项目,android,firebase,google-cloud-firestore,firebaseui,Android,Firebase,Google Cloud Firestore,Firebaseui,我正在使用FirestorePagingAdapter列出Firestore数据库中的图像。我想先将本地广告对象插入列表,然后再将其设置为Recycler视图,以便将广告放置在图像之间。我已经有了创建本地广告并将其插入列表的代码。但是,由于我使用的是FirestorePagingAdapter,在将列表设置为RecyclerView之前,如何修改列表 Query query = db.collection("Wallpapers") .wh

我正在使用FirestorePagingAdapter列出Firestore数据库中的图像。我想先将本地广告对象插入列表,然后再将其设置为Recycler视图,以便将广告放置在图像之间。我已经有了创建本地广告并将其插入列表的代码。但是,由于我使用的是FirestorePagingAdapter,在将列表设置为RecyclerView之前,如何修改列表

    Query query = db.collection("Wallpapers")
                        .whereEqualTo("category", mCategoryName).orderBy("uploadedDate", Query.Direction.DESCENDING);

        PagedList.Config config = new PagedList.Config.Builder()
                        .setEnablePlaceholders(false)
                        .setPrefetchDistance(2)
                        .setPageSize(10)
                        .build();


                FirestorePagingOptions<WallpaperResponse> firestorePagingOptions = new FirestorePagingOptions.Builder<WallpaperResponse>()
                        .setLifecycleOwner(this)
                        .setQuery(query, config, WallpaperResponse.class)
                        .build();

                firestorePagingAdapter = new FirestorePagingAdapter<WallpaperResponse, WallpaperViewHolder>(firestorePagingOptions){

                            @NonNull
                            @Override
                            public WallpaperViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
                                switch (viewType) {
                               /* case NATIVE_AD_VIEW_TYPE:
                                    View unifiedNativeLayoutView = LayoutInflater.from(
                                            viewGroup.getContext()).inflate(R.layout.native_ad,
                                            viewGroup, false);
                                    return new NativeAdViewHolder(unifiedNativeLayoutView);*/
                                    case WALLPAPER_ITEM_VIEW_TYPE:
                                        // Fall through.
                                    default:
                                        View menuItemLayoutView = LayoutInflater.from(viewGroup.getContext())
                                                .inflate(R.layout.fragment_wallpapers_item_grid, viewGroup, false);
                                        return new WallpaperViewHolder(menuItemLayoutView);
                                }
                            }

                            @Override
                            protected void onBindViewHolder(@NonNull WallpaperViewHolder holder, int position, @NonNull WallpaperResponse model) {
                                loadingView.setVisibility(View.GONE);
                                int viewType = getItemViewType(position);
                                switch (viewType) {
                            /*case NATIVE_AD_VIEW_TYPE:
                                UnifiedNativeAd unifiedNativeAd = (UnifiedNativeAd) mWallpapers.get(position);
                                populateNativeAdView(unifiedNativeAd, ((NativeAdViewHolder) holder).getAdView());
                                break;*/
                                    case WALLPAPER_ITEM_VIEW_TYPE:
                                        // fall through
                                    default:
                                        holder.favAnimation.setVisibility(View.GONE);
                                        holder.mode.setVisibility(View.GONE);
                                        holder.author.setVisibility(View.GONE);
                                        WallpaperHelper wallpaperHelper = new WallpaperHelper();
                               ImageLoader.getInstance().displayImage(model.getThumbUrl(), new ImageViewAware(holder.image),
                                                mOptions.build(), new SimpleImageLoadingListener() {
                                                    @Override
                                                    public void onLoadingStarted(String imageUri, View view) {
                                                        super.onLoadingStarted(imageUri, view);
                                                        int color;
                                                    }

                                                    @Override
                                                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                                                        super.onLoadingComplete(imageUri, view, loadedImage);
                                                    }
                                                }, null);

                                }

                                holder.card.setOnClickListener(v -> {

                                });
                            }
                        };

firestorePagingAdapter.notifyDataSetChanged();
        mRecyclerView.setAdapter(Utils.getAnimationAdapter(firestorePagingAdapter));


     private void insertAdsInWallpaperItems() {
            if (unifiedNativeAds.size() <= 0) {
                return;
            }

            int offset = (wallpaperList.size() / unifiedNativeAds.size()) + 1;
            int index = 0;
            for (UnifiedNativeAd ad : unifiedNativeAds) {
                if(index != 0){
                    wallpaperList.add(index, ad);
                }
                index = index + offset;
            }
        }
Query Query=db.collection(“壁纸”)
.whereEqualTo(“category”,mCategoryName).orderBy(“uploadedDate”,Query.Direction.DESCENDING);
PagedList.Config Config=new PagedList.Config.Builder()
.setEnablePlaceholders(false)
.设置预取距离(2)
.setPageSize(10)
.build();
FirestorePagingOptions FirestorePagingOptions=新建FirestorePagingOptions.Builder()
.setLifecycleOwner(此)
.setQuery(查询、配置、响应.class)
.build();
firestorePagingAdapter=新的firestorePagingAdapter(firestorePagingOptions){
@非空
@凌驾
公共墙纸ViewHolder onCreateViewHolder(@NonNull ViewGroup ViewGroup,int-viewType){
开关(视图类型){
/*案例本机\广告\视图\类型:
View unifiedNativeLayoutView=LayoutFlater.from(
viewGroup.getContext())。充气(R.layout.native_ad,
视图组,false);
返回新的NativeAdviewWholder(unifiedNativeLayoutView)*/
案例壁纸\项目\视图\类型:
//失败。
违约:
View menuItemLayoutView=LayoutFlater.from(viewGroup.getContext())
.充气(R.layout.fragment\u壁纸\u项目\u网格、视图组、假);
返回新的壁纸视图持有者(menuItemLayoutView);
}
}
@凌驾
受保护的无效onBindViewHolder(@NonNull wallparkViewHolder,int位置,@NonNull wallpark响应模型){
loadingView.setVisibility(View.GONE);
int viewType=getItemViewType(位置);
开关(视图类型){
/*案例本机\广告\视图\类型:
UNIFIEDNAVIEAD UNIFIEDNAVIEAD=(UNIFIEDNAVIEAD)mWallpapers.get(位置);
PopulateNativeReadView(UnifiedNativeRead,((NativeAdViewHolder)持有者).getAdView());
中断*/
案例壁纸\项目\视图\类型:
//失败
违约:
holder.favAnimation.setVisibility(View.GONE);
holder.mode.setVisibility(视图已消失);
holder.author.setVisibility(View.GONE);
WallpaperHelper=新的WallpaperHelper();
ImageLoader.getInstance().displayImage(model.getThumbUrl(),new ImageViewAware(holder.image),
mOptions.build(),新的SimpleImageLoadingListener(){
@凌驾
public void onLoadingStarted(字符串imageUri,视图){
super.onLoadingStarted(imageUri,视图);
内色;
}
@凌驾
public void onLoadingComplete(字符串imageUri、视图视图、位图加载图像){
super.onLoadingComplete(imageUri、视图、LoadeImage);
}
},空);
}
holder.card.setOnClickListener(v->{
});
}
};
firestorePagingAdapter.notifyDataSetChanged();
mRecyclerView.setAdapter(Utils.getAnimationAdapter(firestorePagingAdapter));
私有void insertadsinwallperItems(){

如果(unifiednavieads.size(),您可以尝试以下方法。虽然它不会改变原始列表大小,但可以帮助您将广告数据压缩到列表项中

firestorePagingOptions.value = FirestorePagingOptions.Builder<Story>()
                .setQuery(factsQuery, Source.DEFAULT, config) {
                    val story = it.toObject(Story::class.java)!!
                    //Modify your data here
                    story //return the modified object 
                }.build()
firestorePagingOptions.value=firestorePagingOptions.Builder()
.setQuery(factsQuery,Source.DEFAULT,config){
val story=it.toObject(story::class.java)!!
//在此处修改您的数据
story//返回修改过的对象
}.build()

问题是什么?这段代码中到底有什么不符合您的预期?目前,使用FirestorePagingOptions和FirestorePagingAdapter,从查询返回的任何数据都会自动设置为recyeclerView。我想修改Firestore返回的数据,在两者之间插入本机广告,然后在n recycler视图。在适配器中设置此数据之前,我需要访问它