Skip to content

Repository files navigation

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 ActivitypublicclassMainActivityextendsAppCompatActivity{
privateAQueryaq;
@OverrideprotectedvoidonCreate(@NullableBundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
aq = newAQuery(this);
}
}
// AQuery in FragmentpublicclassMainFragmentextendsFragment{
privateAQueryaq;
@Nullable@OverridepublicViewonCreateView(LayoutInflaterinflater,
@NullableViewGroupcontainer,
@NullableBundlesavedInstanceState) {
returninflater.inflate(R.layout.fragment_home, container, false);
}
@OverridepublicvoidonViewCreated(Viewview, @NullableBundlesavedInstanceState) {
super.onViewCreated(view, savedInstanceState);
aq = newAQuery(getActivity());
}
}
// AQuery in ViewHolderpublicclassViewHolderextendsRecyclerView.ViewHolder{
privateAQueryaq;
publicViewHolder(ViewitemView) {
super(itemView);
aq = newAQuery(itemView.getContext(), itemView);
}
}

Query Activity :

// Fast intentaq.open(HomeActivity.class);
// Custom intentIntentintent = newIntent(this, HomeActivity.class);
intent.putExtra("id",1);
aq.open(intent);
// Intent transition from left and rightaq.openFromRight(HomeActivity.class);
aq.openFromLeft(HomeActivity.class);
aq.openFromRight(intent);
aq.openFromLeft(intent);
// Close activity transitionaq.closeToRight();
aq.closeToLeft();

Query View :

// OnClickListeneraq.id(R.id.login).click(v -> {
// Do stuff
});
// Check is text not emptybooleanvalid = aq.id(R.id.input_email).isValid();
// Get text value of view is avaliableStringemail = aq.id(R.id.input_email).text();
// Set Visibilty Goneaq.id(R.id.input_email).hide();
// Set Visibilty Visibleaq.id(R.id.input_email).show();
// Cast viewDefaultTextFielddefaultTextField = aq.id(R.id.input_email).as(DefaultTextField.class);
// Active state Viewaq.id(R.id.input_email).active();
aq.id(R.id.input_email).inActive();
// If you want rounded imageaq.id(R.id.image).image(user.getAvatar_url()).rounded();
// If you want set from drawableaq.id(R.id.image).image(R.drawable.profile);

Query Toas :

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

Query Network :

// Ajax getaq.ajax("https://api.github.com/users/ar-android")
.get()
.showLoading()
.toObject(GithubUsers.class, (user, error) -> {
// Do stuff
});
// Ajax POST formMap<String, String> params = newHashMap<>();
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 preferencesaq.saveString("token", response.getData().getToken());
// Grab string from shared preferencesStringtoken = aq.grabString("token");

Query SQLite :

//Storing data to SQLiteMap<String, Object> data = newHashMap<>();
data.put("nama", "Putri Nuraini");
data.put("email", "alahmadrosid@gmail.com");
aq.sql().table("user").insert(data);
// Get All row from tableList<Map<String, String>> user = aq.sql().table("user").all();
// Update row from table by idbooleanupdate = aq.sql().table("user").update(3, data);
// Get row table by idMap<String, String> user = aq.sql().table("user").get(3);
// Get table by first rowMap<String, String> user = aq.sql().table("user").first();
// Get table by last rowMap<String, String> user = aq.sql().table("user").last();
// Delete table by idbooleandelete = aq.sql().table("user").delete(2);
// Clear database sqliteaq.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.

About

Utility query for android

Topics

Resources

Stars

40 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages