Giter Site home page Giter Site logo

webianks / playstoreparalleldownload Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 9.0 1.71 MB

:cyclone: Demo logic to download/update apps in parallel inside recyclerview like AppStore.

License: MIT License

Java 100.00%
play-store downloader update parallel-download asynctask thread thread-pool-executer

playstoreparalleldownload's Introduction

PlayStoreParallelDownload

Play store downloads/updates app in sequence because of the performance issues but still there are the cases when you need to download/upload things in parallel like AppStore or WhatsApp.

Problem Statement

  • Download apps in parallel.
  • Update their progress in recyclerview item.

Solution

It can be achieved through using:

  • Service - For not messing with the UI
  • AsyncTask - Separate worker thread inside service.
  • THREAD_POOL_EXECUTOR - Feature of AsyncTask to run multiple asynctasks in different threads.
  • LocalBroadcastManager - To notify about the progress of download.

Download

License

MIT License

Copyright (c) 2017 Ramankit Singh

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

playstoreparalleldownload's People

Contributors

webianks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

playstoreparalleldownload's Issues

update RecyclerView after on click button plus

I have a shopping cart In this cart, I want to click on the plus button My RecyclerView will be upgraded

In this cart, I want to click on the mines button My RecyclerView will be upgraded
my code :

``
`public class ShopCartAdapter extends RecyclerView.Adapter<ShopCartAdapter.ShopCartHolder> {
List mDataset;
Context context;
String email, password;
List list;
TestTest adapter;

public void update(List<ShopCartGet> array) {
    mDataset = array;
    notifyDataSetChanged();
}



public class ShopCartHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    TextView title, price;
    TextView number_order, priceall;
    ImageView img, delete, minus, plus;
    Spinner sp;
    TextView id;
    int currentNos;
    int ids = 0;

    public void update(List<ShopCartGet> list) { 
        mDataset = list; 
        notifyDataSetChanged(); 
    }
    public void delete(int position) {
        list.remove(position);
        notifyItemRemoved(position);
    }

    public void increment() {
        currentNos = Integer.parseInt(number_order.getText().toString());
        number_order.setText(String.valueOf(++currentNos));
        ids = Integer.parseInt(id.getText().toString());
        email = ShopCart.string_from_sp;
        password = ShopCart.string_from_sp1;
    }

    public void Decrease() {
        currentNos = Integer.parseInt(number_order.getText().toString());
        number_order.setText(String.valueOf(--currentNos));
        ids = Integer.parseInt(id.getText().toString());
        email = ShopCart.string_from_sp;
        password = ShopCart.string_from_sp1;
    }

    public void update() {
        String BASE_URL = "http://laravel.cahoo.ir/json/android/update_basket.php";
        StringRequest stringRequest = new StringRequest(Request.Method.POST, BASE_URL, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("email", email);
                params.put("order_id", String.valueOf(ids));
                params.put("number_order", String.valueOf(currentNos));
                params.put("password", password);

                return params;
            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                return super.getHeaders();
            }
        };
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(20000, 1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        RequestQueue queue = Volley.newRequestQueue(context);
        queue.add(stringRequest);

    }

    public void delete() {

        String BASE_URL = "xxx";


        StringRequest stringRequest = new StringRequest(Request.Method.POST, BASE_URL, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {


            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {


            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<>();
                params.put("email", email);
                params.put("order_id", String.valueOf(ids));
                params.put("number_order", String.valueOf(currentNos));
                params.put("password", password);


                return params;
            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                return super.getHeaders();
            }
        };
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(20000, 1, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        RequestQueue queue = Volley.newRequestQueue(context);
        queue.add(stringRequest);

        notifyDataSetChanged();
    }

    public ShopCartHolder(View itemView) { 
        super(itemView);
        title = (TextView) itemView.findViewById(R.id.text_info);
        number_order = (TextView) itemView.findViewById(R.id.number_order);
        price = (TextView) itemView.findViewById(R.id.price);
        priceall = (TextView) itemView.findViewById(R.id.priceall);
        img = (ImageView) itemView.findViewById(R.id.image_mahsol);
        delete = (ImageView) itemView.findViewById(R.id.delet);
        minus = (ImageView) itemView.findViewById(R.id.minus);
        plus = (ImageView) itemView.findViewById(R.id.plus);
        id = (TextView) itemView.findViewById(R.id.ids);

        delete.setOnClickListener(this); //button onclick listener


        plus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                increment();

                update();


            }
        });
        minus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Decrease();
                update();

            }
        });
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i("salam", "imag");
                delete();
            }
        });

    }



    @Override
    public void onClick(View v) {
        delete(getAdapterPosition()); //calls the method above to delete
    }


}

public ShopCartAdapter(Context context, List<ShopCartGet> myDataset) {
    this.mDataset = myDataset;
    this.context = context;

}

@Override
public ShopCartAdapter.ShopCartHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.sample_shop_cart, parent, false);
    ShopCartAdapter.ShopCartHolder dataObjectHolder = new ShopCartAdapter.ShopCartHolder(view);
    return dataObjectHolder;
}

@Override
public void onBindViewHolder(final ShopCartAdapter.ShopCartHolder holder, final int position) {

    holder.title.setText(mDataset.get(position).title);
    holder.price.setText(mDataset.get(position).price);
    holder.number_order.setText(mDataset.get(position).number_order);
    holder.id.setText(String.valueOf(mDataset.get(position).id));
    holder.priceall.setText(mDataset.get(position).pricall);

    Picasso.with(context)
            .load(mDataset.get(position).img)
            .placeholder(R.drawable.logolo)
            .into(holder.img);
}


@Override
public int getItemCount() {
    return mDataset.size();
}

public void delete(int position) { //removes the row
    mDataset.remove(position);
    notifyItemRemoved(position);
}

}
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.