-
Notifications
You must be signed in to change notification settings - Fork 0
Code Documentation
Maël Drapier edited this page Nov 18, 2018
·
6 revisions
Happy Niglo is an Imgur client android app.
It's written in Java/Kotlin on Android Studio, and is built with gradle.
We are using CircleImageView, Retrofit and Glide.
In the app/build.gradle file:
dependencies {
...
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
...
}Here are the Imgur API calls we are using (thanks to Retrofit)
In ImgurApi.java:
- GET calls:
@GET("account/{user}/avatar")
Call<Avatar> getAvatar(@Path("user") String user);
@GET("account/{user}/images")
Call<ImageList> getUserImages(@Path("user") String user);
@GET("account/{user}/favorites")
Call<AlbumList> getUserFavorites(@Path("user") String user);
@GET("gallery/search/{sort}/{window}/{page}")
Call<AlbumList> getSearchedImages(@Path("sort") Sort sort, @Path("window") Window window, @Path("page") int page, @Query("q") String query);- POST calls:
@POST("{type}/{imageHash}/favorite")
Call<Response> switchFavorites(@Path("type") String type, @Path("imageHash") String hash);
@FormUrlEncoded
@POST("image/{imageHash}")
Call<Response> updateImageInfos(@Path("imageHash") String hash, @Field("title") String title, @Field("description") String desc);
@POST("image")
Call<ResponseBody> getUploadResponse(@Body RequestBody body);
@POST("gallery/{Hash}/vote/{vote}")
Call<Response> toogleLike(@Path("Hash") String hash, @Path("vote") Vote vote);- DELETE calls:
@DELETE("image/{imageHash}")
Call<Response> deleteImage(@Path("imageHash") String hash);Lists of Images and albums received after an Imgur API call are put in the ImagesList and AlbumList classes.
In ImageList.java:
public class ImageList {
public List<Image> data;
public class Image {
public String id;
public String deletehash;
public String title;
public String description;
public String views;
public String link;
public boolean is_album;
}
}In AlbumList.java:
public class AlbumList {
public List<Album> data;
public class Album {
public String id;
public String title;
public String description;
public String link;
public String vote;
public Integer views;
public boolean favorite;
public boolean is_album;
public List<Image> images;
}
}The app usage is based on several tabs grouped in a navigation menu, descirbed in activity_main_drawer.xml
(See the User Documentation for more details).
On an selection in this navigation menu, the onNavigationItemSelected function from MainActivity.kt is called.
override fun onNavigationItemSelected(item: MenuItem): Boolean {
// Handle navigation view item clicks here.
when (item.itemId) {
R.id.nav_my_pictures -> {
DisplayUserImages()
}
R.id.nav_search -> {
SearchImages()
}
R.id.nav_upload -> {
UploadImage()
}
R.id.nav_favorites -> {
DisplayFavoriteImages()
}
R.id.nav_logout -> {
LogoutUser()
}
}
drawer_layout.closeDrawer(GravityCompat.START)
return true
}