آموزش های این وب سایت به صورت رایگان در دسترس است. اطلاعات بیشتر
بروز خطا
   [message]
اشتراک در سوال
رای ها
[dataList]

اسکرول سریع روی ریسایکلر ویو و کرش برنامه

احسان  8 سال پیش  8 سال پیش
0 0

سلام دوستان من توی برنامم یه ریسایکلر ویو دارم و یک اتصال به سرور که اطلاعات رو از سرور میگیره و ریسایکلر رو با داده های سرور می سازه. مشکلی که من دارم اینه که وقتی کاربر سریع اسکرول میکنه یه دفعه اکتیویتی بسته میشه و یا اینکه کلا برنامه کرش میکنه.
این فرگمنتی هستش که توش از ریسایکلر ویو استفاده کردم:

 
 private RecyclerView singleListRecycler;
  private RecyclerView.LayoutManager rtlGridLayoutManager;
  private RecyclerView.Adapter weekAdapter;
  private List<PList> singleList = new ArrayList<PList>();

  private String prgCode;
  private LinearLayout layoutLoading;
  private TextView txtNoGood;

  int totalPage = 1;
  int currentPage = 1;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_product, container, false);
    inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    syncBasket();

    user_auth = G.getPremiumState()[0];
    user_pass = G.getPremiumState()[1];
    user_mobile = G.getPremiumState()[2];

    if (user_auth.equals("") || user_mobile.equals("") || user_pass.equals("")) {

      Toast.makeText(getContext(), "خطایی رخ داده است ! مجدد تلاش کنید.", Toast.LENGTH_SHORT).show();
      Intent goToStartup = new Intent(getContext(), ActivityStartup.class);
      getActivity().finish();
      startActivity(goToStartup);
    }


    singleListRecycler = (RecyclerView) view.findViewById(R.id.singleListRecycler);
    layoutLoading = (LinearLayout) view.findViewById(R.id.layout_loading);
    txtNoGood = (TextView) view.findViewById(R.id.txt_no_good);

    Bundle bundle = getActivity().getIntent().getExtras();
    if (bundle != null) {
      prgCode = bundle.getString("PRG_CODE");
    } else {
      Intent goBack = new Intent(getContext(), ActivityMainProducts.class);
      startActivity(goBack);

    }

    //Preparing data from server for this group
    getSingleGroup(prgCode, currentPage);

    //Add Two Listener to RecyclerView
    singleListRecycler.addOnScrollListener(new PicassoOnScrollListener(context));
    singleListRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() {

      @Override
      public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);

        if (dy < 0) {
          // Recycle view scrolling up ...
          // Toast.makeText(activitySingleGroup, "Top", Toast.LENGTH_SHORT).show();

        } else if (dy > 0) {

          if (!singleListRecycler.canScrollVertically(View.SCROLL_AXIS_VERTICAL)) {

            currentPage = currentPage + 1;

            if (currentPage > totalPage) {
              currentPage = totalPage;
              layoutLoading.setVisibility(View.GONE);
            } else {
              layoutLoading.setVisibility(View.VISIBLE);
              getSingleGroup(prgCode, currentPage);
            }

          }
        }
      }
    });

    return view;
  }

  private void getSingleGroup(String code, int page) {

    if (singleList.size() == 0) {
      G.showProgress(getActivity());
    }

    APIService apiService = ServiceGenerator.createService(APIService.class, user_auth, user_pass);

    String url = "prg/" + code + "/" + page;
    Call<ProductModel> call = apiService.getNormalList(url);

    call.enqueue(new Callback<ProductModel>() {

      @Override
      public void onResponse(Call<ProductModel> call, Response<ProductModel> response) {

        layoutLoading.setVisibility(View.GONE);
        Log.i("LOGO", "Code of  Normal is: " + response.code());

        if (singleList.size() == 0) {
          G.dismissProgress();
        }

        if (response.code() == 200) {

          ProductModel newMainCategory = response.body();

          totalPage = newMainCategory.getPTotalPage();

          singleList.addAll(newMainCategory.getPList());

          rtlGridLayoutManager = new RtlGridLayoutManager(getContext(), 1);
          singleListRecycler.setLayoutManager(rtlGridLayoutManager);
          weekAdapter = new BaseListAdapter(singleList, (ActivitySingleGroup) getActivity());

          if (singleList.size() > 0) {
            singleListRecycler.setAdapter(weekAdapter);
          } else {
            singleListRecycler.setVisibility(View.GONE);
            txtNoGood.setVisibility(View.VISIBLE);
          }
        } else {

          singleListRecycler.setVisibility(View.GONE);
          txtNoGood.setVisibility(View.VISIBLE);
        }
      }

      @Override
      public void onFailure(Call<ProductModel> call, Throwable t) {
        Log.i("LOGO", "Error s: " + t.toString());

        if (singleList.size() == 0) {
          G.dismissProgress();
        }

        layoutLoading.setVisibility(View.GONE);
        singleListRecycler.setVisibility(View.GONE);
        txtNoGood.setVisibility(View.VISIBLE);
      }

    });
  }


 و این هم ادپتر من هستش که برای ریسایکلر ویو استفاده کردم.

 
public class BaseListAdapter extends RecyclerView.Adapter<BaseListAdapter.ViewHolder> {
  private List<PList> menuItems;
  private Context mContext;
  private ActivitySingleGroup activitySingleGroup;
  private int lastPosition = -1;

  public BaseListAdapter(List<PList> menuItems, Context mContext) {
    this.menuItems = menuItems;
    this.mContext = mContext;
    this.activitySingleGroup = (ActivitySingleGroup) mContext;
  }

  public static class ViewHolder extends RecyclerView.ViewHolder {

    TextView txtName;
    TextView txtPrice;
    ImageView imgDefault;
    LinearLayout parentLayout;
    CoordinatorLayout coordinatorLayout;

    public ViewHolder(View v) {
      super(v);

      txtName = (TextView) v.findViewById(R.id.txtName);
      txtPrice = (TextView) v.findViewById(R.id.txtPrice);
      imgDefault = (ImageView) v.findViewById(R.id.img_defaultImage);
      parentLayout = (LinearLayout) v.findViewById(R.id.parentLayout);
      coordinatorLayout = (CoordinatorLayout) v.findViewById(R.id.coordinatorLayout);

    }
  }

  @Override
  public BaseListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    // Create a new View
    final View v = LayoutInflater.from(activitySingleGroup).inflate(R.layout.activity_normal_group_recycler, parent, false);
    ViewHolder vh = new ViewHolder(v);
    return vh;
  }

  @Override
  public void onBindViewHolder(final ViewHolder holder, final int position) {

    //Download and Load Default Image from server into imgDefault ImageView
    Picasso picasso;
    OkHttpClient client = null;
    String url = "https://bartarinapp-irdeveloper.rhcloud.com/api/images/download/";

    //Handel situations that default image variables will be null
    if (menuItems.get(position).getPDefaultImage() != null &&
      menuItems.get(position).getPDefaultImage().getDefault() != null) {

      if ((menuItems.get(position).getPDefaultImage().getDefault()) &&
        (menuItems.get(position).getPDefaultImage().getIId() != null)) {

        url += menuItems.get(position).getPDefaultImage().getIId();

        client = ServerClass.setAuthImage();

        picasso = new Picasso.Builder(mContext)
          .downloader(new OkHttp3Downloader(client))
          .listener(new Picasso.Listener() {
            @Override
            public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
              //Here your log
              Log.i("I_ERROR", "Error is: " + exception.toString());
            }
          })
          .build();

      } else {
        url = null;
        picasso = new Picasso.Builder(mContext)
          .listener(new Picasso.Listener() {
            @Override
            public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
              //Here your log
              Log.i("I_ERROR", "Error is: " + exception.toString());
            }
          })
          .build();

      }
    } else {
      url = null;
      picasso = new Picasso.Builder(mContext)
        .listener(new Picasso.Listener() {
          @Override
          public void onImageLoadFailed(Picasso picasso, Uri uri, Exception exception) {
            //Here your log
            Log.i("I_ERROR", "Error is: " + exception.toString());
          }
        })
        .build();
    }


    picasso.cancelRequest(holder.imgDefault);
    if (url != null && url.length() > 0) {

      //put here picaso image load code
      picasso.load(url)
        .tag(PicassoOnScrollListener.TAG)
        .placeholder(R.drawable.loading_01)
        .error(R.drawable.loading_02)
        .into(holder.imgDefault);

    } else {
      holder.imgDefault.setImageResource(R.drawable.ic_empty_white_box);
    }

    holder.txtName.setText(menuItems.get(position).getPName());
    holder.txtPrice.setText(String.valueOf(menuItems.get(position).getPPrice()));
    holder.parentLayout.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {

        prepareBottomSheet(view, position, holder.coordinatorLayout);
      }
    });
  }

  @Override
  public int getItemCount() {
    if (menuItems.size() > 0) {

      return menuItems.size();

    } else {
      return 0;
    }

  }

و این هم پیامی که در لاگ کت میگیرم:

 
java.lang.reflect.InvocationTargetException
  at java.lang.reflect.Method.invoke(Native Method)
  at com.google.firebase.FirebaseApp.zza(Unknown Source)
  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
  at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
  at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)
  at android.content.ContentProvider.attachInfo(ContentProvider.java:1734)
  at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
  at android.app.ActivityThread.installProvider(ActivityThread.java:6420)
  at android.app.ActivityThread.installContentProviders(ActivityThread.java:6012)
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5951)
  at android.app.ActivityThread.-wrap3(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:154)
  at android.app.ActivityThread.main(ActivityThread.java:6776)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
  Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/internal/zzapn;
  at com.google.android.gms.internal.zzbku.<clinit>(Unknown Source)
  at com.google.android.gms.internal.zzbku.initialize(Unknown Source)
  at com.google.firebase.crash.FirebaseCrash.getInstance(Unknown Source)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.google.firebase.FirebaseApp.zza(Unknown Source)
  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
  at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
  at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)
  at android.content.ContentProvider.attachInfo(ContentProvider.java:1734)
  at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
  at android.app.ActivityThread.installProvider(ActivityThread.java:6420)
  at android.app.ActivityThread.installContentProviders(ActivityThread.java:6012)
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5951)
  at android.app.ActivityThread.-wrap3(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:154)
  at android.app.ActivityThread.main(ActivityThread.java:6776)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
  Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.internal.zzapn" on path: DexPathList[[zip file "/data/app/codenevisha.com.apps.bartarinapp-1/base.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_dependencies_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_0_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_1_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_2_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_3_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_4_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_5_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_6_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_7_apk.apk", zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_8_apk.apk",
  zip file "/data/app/codenevisha.com.apps.bartarinapp-1/split_lib_slice_9_apk.apk"],
  nativeLibraryDirectories=[/data/app/codenevisha.com.apps.bartarinapp-1/lib/arm, /system/lib, /vendor/lib]]
  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
  at com.google.android.gms.internal.zzbku.<clinit>(Unknown Source)
  at com.google.android.gms.internal.zzbku.initialize(Unknown Source)
  at com.google.firebase.crash.FirebaseCrash.getInstance(Unknown Source)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.google.firebase.FirebaseApp.zza(Unknown Source)
  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
  at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
  at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
  at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)
  at android.content.ContentProvider.attachInfo(ContentProvider.java:1734)
  at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
  at android.app.ActivityThread.installProvider(ActivityThread.java:6420)
  at android.app.ActivityThread.installContentProviders(ActivityThread.java:6012)
  at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5951)
  at android.app.ActivityThread.-wrap3(ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:154)
  at android.app.ActivityThread.main(ActivityThread.java:6776)
  at java.lang.reflect.Method.invoke(Native Method)

 
 برای این سوال پاسخی وجود ندارد.

پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .