Skip to content
This repository has been archived by the owner on Mar 6, 2020. It is now read-only.

iDerly/iDerly-android

Repository files navigation

iDerly-android

How to use HttpPostRequest(String url[, Object mixed...])

Package:

import com.iderly.control.HttpPostRequest;

Optional:

import com.iderly.control.HttpPostRequestListener;

Class:

public abstract HttpPostRequest extends AsyncTask<Void, Void, String>

Constructor:

public HttpPostRequest(String url, Object... mixed)

Methods:

public void send()

public HttpPostRequest addParameter(String name, String value)

public HttpPostRequest addParameters(Pair<String, String>... parameters)

public HttpPostRequest addParameters(List<Pair<String, String>> parameters)

Never forget to send the request!

Basic Usage:

new HttpPostRequest("https://github.com/") {
    @Override
    public void onFinish(int statusCode, String responseText) {
        // Do something here
    }
}.addParameter("param1", "value1")
    .addParameter("param2", "value2")
    .send();

Advanced Usage:

/*
    Block MainUI Thread with
        ProgressDialog.show(Context context, CharSequence title, CharSequence message, bool indeterminate)
*/
ProgressDialog pd = ProgressDialog.show(getActivity(), null, "Loading...", true);

But... how do you dismiss the dialog when the request is finish?

new HttpPostRequest("https://github.com/", pd) {
    @Override
    public void onFinish(int statusCode, String responseText) {
        ((ProgressDialog) this.mixed[0]).dismiss();  // dismiss the dialog, releasing the block in MainUI Thread
    }
}.addParameter("param1", "value1")
    .addParameter("param2", "value2")
    .send();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages