Git Product home page Git Product logo

gonnect's Introduction

Gonnect

An elegant Android HTTP/HTTP2 library with great features.

Installation

To add Gonnect to your project, simply add the following dependency to your module's build.gradle file:

implementation 'com.github.poorya-abbasi:Gonnect:v1.3'

Alternatively, add app/src/main/java/org/marlik/innovelopers/gonnect/Gonnect.java from this repository to your project (don't forget to fix package name in the first line of the file) and then add the following dependencies to your module's build.gradle file:

implementation 'com.squareup.okhttp3:okhttp:3.14.6'
implementation 'com.android.volley:volley:1.1.1'

Usage

Sending GET requests

// "tag" is a unique string for the request, which can be used later to cancel the request

Gonnect.getCancelableData(urlString, CurrentActivity.this, tag, response -> {

    // This part is called when the request is successful
    // "response" will contain the recevied data

}, exception -> {

    // This part is called when the request is unsuccessful
    // "exception" is an instance of IOException

});

Sending GET Requests and launching an activity afterwards

// "tag" is a unique string for the request, which can be used later to cancel the request

Gonnect.getCancelableDataAndLaunchActivity(urlString, tag, exception -> {
        
        // This part is called when the request is unsuccessful
        // "exception" is an instance of IOException

}, DestinationActivity.class, CurrentActivity.this);

The result is automatically saved into the "response" extra string in the destination activity:

// In DestinationActivity.java

String response = getIntent().getStringExtra("response")

Sending POST requests

ContentValues cv = new ContentValues();
cv.put("firstParameter", "someValue");
cv.put("secondParameter", "someOtherValue");

// "tag" is a unique string for the request, which can be used later to cancel the request

Gonnect.sendCancelableRequest(urlString, CurrentActivity.this, cv, tag, response -> {

    // This part is called when the request is successful
    // "response" will contain the recevied data

}, exception -> {
    
    // This part is called when the request is unsuccessful
    // "exception" is an instance of IOException

});

Sending POST Requests and launching an activity afterwards

ContentValues cv = new ContentValues();
cv.put("firstParameter", "someValue");
cv.put("secondParameter", "someOtherValue");

// "tag" is a unique string for the request, which can be used later to cancel the request

Gonnect.sendCancelableRequestAndLaunchActivity(urlString, cv, tag, exception -> {
        
        // This part is called when the request is unsuccessful
        // "exception" is an instance of IOException

}, DestinationActivity.class, CurrentActivity.this);

The result is automatically saved into the "response" extra string in the destination activity:

// In DestinationActivity.java

String response = getIntent().getStringExtra("response")

Canceling a request

Gonnect.cancelRequest(tag);

Some other important notes

  • Don't forget to add the following line to your project's AndroidManifest.xml, above the <application> tag:

    <uses-permission android:name="android.permission.INTERNET" />

  • If you are calling HTTP URLs, which are not as secure as HTTPS calls, you should add the following property inside the <application> tag in your project's AndroidManifest.xml:

    android:usesCleartextTraffic="true"

gonnect's People

Contributors

spneshaei avatar

Stargazers

Poorya Abbasi avatar Sepand Haghighi avatar  avatar

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.