Giter Site home page Giter Site logo

aquery's Introduction

AQuery

AQuery is like JQuery but it for android. AQuery allows the developer to write less and do more for managing element of android like Activity, View, Network, Caching and many more.

Getting Started

To use this library Add in you top build.gradle :

allprojects {
    repositories {
      maven { url 'https://jitpack.io' }
    }
  }

Setup java 8 compiler for enable lambada expression in you app build.gradle :

compileOptions {
  sourceCompatibility 1.8
  targetCompatibility 1.8
}

Add the dependency in you app build.gradle :

implementation 'com.github.ar-android:AQuery:1.0.3'

Use Case

As we have metion before AQuery is just like JQuery but for quering in android. Bellow example of use case.

Initializing AQuery :

// AQuery in Activity
public class MainActivity extends AppCompatActivity{

    private AQuery aq;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        aq = new AQuery(this);
    }
}

// AQuery in Fragment
public class MainFragment extends Fragment{

    private AQuery aq;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater,
                             @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_home, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        aq = new AQuery(getActivity());
    }
}

// AQuery in ViewHolder
public class ViewHolder extends RecyclerView.ViewHolder{

    private AQuery aq;

    public ViewHolder(View itemView) {
        super(itemView);
        aq = new AQuery(itemView.getContext(), itemView);
    }
}

Query Activity :

// Fast intent
aq.open(HomeActivity.class);

// Custom intent
Intent intent = new Intent(this, HomeActivity.class);
intent.putExtra("id",1);
aq.open(intent);

// Intent transition from left and right
aq.openFromRight(HomeActivity.class);
aq.openFromLeft(HomeActivity.class);
aq.openFromRight(intent);
aq.openFromLeft(intent);

// Close activity transition
aq.closeToRight();
aq.closeToLeft();

Query View :

// OnClickListener
aq.id(R.id.login).click(v -> {
  // Do stuff
});

// Check is text not empty
boolean valid = aq.id(R.id.input_email).isValid();

// Get text value of view is avaliable
String email = aq.id(R.id.input_email).text();

// Set Visibilty Gone
aq.id(R.id.input_email).hide();

// Set Visibilty Visible
aq.id(R.id.input_email).show();

// Cast view
DefaultTextField defaultTextField = aq.id(R.id.input_email).as(DefaultTextField.class);

// Active state View
aq.id(R.id.input_email).active();
aq.id(R.id.input_email).inActive();

// If you want rounded image
aq.id(R.id.image).image(user.getAvatar_url()).rounded();

// If you want set from drawable
aq.id(R.id.image).image(R.drawable.profile);

Query Toas :

// Simple toas
aq.snack("Message");
aq.toast("Message");

Query Network :

// Ajax get
aq.ajax("https://api.github.com/users/ar-android")
        .get()
        .showLoading()
        .toObject(GithubUsers.class, (user, error) -> {
            // Do stuff
        });

// Ajax POST form
Map<String, String> params = new HashMap<>();
params.put("email", aq.id(R.id.email).text());
params.put("password", aq.id(R.id.password).text());
aq.ajax("https://ocit-tutorial.herokuapp.com/index.php")
        .postForm(params)
        .showLoading()
        .response((response, error) -> {
            if (response != null){
                aq.openFromRight(MainActivity.class);
            }
        });

Query Shared Preferences :

// Save string to shared preferences
aq.saveString("token", response.getData().getToken());

// Grab string from shared preferences
String token = aq.grabString("token");

Query SQLite :

//Storing data to SQLite
Map<String, Object> data = new HashMap<>();
data.put("nama", "Putri Nuraini");
data.put("email", "[email protected]");
aq.sql().table("user").insert(data);

// Get All row from table
List<Map<String, String>> user = aq.sql().table("user").all();

// Update row from table by id
boolean update = aq.sql().table("user").update(3, data);

// Get row table by id
Map<String, String> user = aq.sql().table("user").get(3);

// Get table by first row
Map<String, String> user = aq.sql().table("user").first();

// Get table by last row
Map<String, String> user = aq.sql().table("user").last();

// Delete table by id
boolean delete = aq.sql().table("user").delete(2);

// Clear database sqlite
aq.sql().clearDb();

And AQuery have a lot of API check it on Documentation

Built With

  • Okhttp - Networking Library.
  • Glide - Image Loading and caching.
  • Gson - A Java serialization/deserialization for JSON.

Authors

See also the list of contributors who participated in this project.

License

Copyright 2017 Ahmad Rosid

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

aquery's People

Contributors

ahmadrosid avatar ar-android avatar awalmubarak 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aquery's Issues

on certificate issue it's showing network error

There is a scenario where i have to show pop up to bypass certificate issue but using aquery library i am not able to distinguish that the error is generated due to certificate or there is some network issue.
Aquery Issue

Error when run in my app

new AQuery(myActivity).id(R.id.imageView).image(R.drawable.myImage).rounded()

java.lang.NoSuchMethodError: No virtual method into(Landroid/widget/ImageView;)Lcom/bumptech/glide/request/target/Target; in class Lcom/bumptech/glide/RequestBuilder; or its super classes

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.