├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_clear.png
│ │ │ │ ├── ic_close.png
│ │ │ │ ├── ic_forward.png
│ │ │ │ ├── ic_heart.png
│ │ │ │ ├── ic_reload.png
│ │ │ │ └── ic_backbutton.png
│ │ │ ├── drawable-ldpi
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_clear.png
│ │ │ │ ├── ic_close.png
│ │ │ │ ├── ic_forward.png
│ │ │ │ ├── ic_heart.png
│ │ │ │ └── ic_reload.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_clear.png
│ │ │ │ ├── ic_close.png
│ │ │ │ ├── ic_forward.png
│ │ │ │ ├── ic_heart.png
│ │ │ │ ├── ic_reload.png
│ │ │ │ └── ic_backbutton.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_clear.png
│ │ │ │ ├── ic_close.png
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_heart.png
│ │ │ │ ├── ic_reload.png
│ │ │ │ ├── ic_forward.png
│ │ │ │ └── ic_backbutton.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── ic_clear.png
│ │ │ │ ├── ic_close.png
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_heart.png
│ │ │ │ ├── ic_forward.png
│ │ │ │ ├── ic_reload.png
│ │ │ │ ├── ic_backbutton.png
│ │ │ │ ├── round_layout.xml
│ │ │ │ └── round_layout_alternate.xml
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── ic_edit.png
│ │ │ │ ├── ic_clear.png
│ │ │ │ ├── ic_close.png
│ │ │ │ ├── ic_heart.png
│ │ │ │ ├── ic_reload.png
│ │ │ │ ├── ic_forward.png
│ │ │ │ └── ic_backbutton.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── anim
│ │ │ │ ├── slide_in_left.xml
│ │ │ │ ├── fade_in.xml
│ │ │ │ ├── hide_to_bottom.xml
│ │ │ │ ├── slide_in_right.xml
│ │ │ │ ├── slide_out_left.xml
│ │ │ │ ├── rotate.xml
│ │ │ │ ├── fade_out.xml
│ │ │ │ ├── scale_down.xml
│ │ │ │ ├── jump_from_down.xml
│ │ │ │ └── jump_to_down.xml
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── menu
│ │ │ │ └── itemmenu.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ └── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── masonrylayoutitem.xml
│ │ │ │ └── activity_user.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── saurabhkumar
│ │ │ │ └── downz
│ │ │ │ ├── CustomClasses
│ │ │ │ ├── ItemDecoration.java
│ │ │ │ ├── SpacesItemDecoration.java
│ │ │ │ ├── MasonryView.java
│ │ │ │ ├── User.java
│ │ │ │ └── MasonryAdapter.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── UserActivity.java
│ │ └── AndroidManifest.xml
│ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── saurabhkumar
│ │ │ └── downz
│ │ │ ├── UserActivityTest.java
│ │ │ └── ExampleInstrumentedTest.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── saurabhkumar
│ │ └── downz
│ │ └── ExampleUnitTest.java
├── proguard-rules.pro
└── build.gradle
├── downzlibrary
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ └── strings.xml
│ │ │ └── anim
│ │ │ │ ├── slide_in_left.xml
│ │ │ │ ├── fade_in.xml
│ │ │ │ ├── hide_to_bottom.xml
│ │ │ │ ├── slide_in_right.xml
│ │ │ │ ├── slide_out_left.xml
│ │ │ │ ├── rotate.xml
│ │ │ │ ├── fade_out.xml
│ │ │ │ ├── scale_down.xml
│ │ │ │ ├── jump_from_down.xml
│ │ │ │ └── jump_to_down.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── downzlibrary
│ │ │ ├── Utilities
│ │ │ ├── CacheManagerInterface.java
│ │ │ └── CacheManager.java
│ │ │ ├── DataTypes
│ │ │ ├── Type.java
│ │ │ ├── JsonObject.java
│ │ │ ├── XmlType.java
│ │ │ ├── BitMap.java
│ │ │ └── JsonArray.java
│ │ │ ├── ListnerInterface
│ │ │ └── HttpListener.java
│ │ │ ├── Parameters
│ │ │ ├── HeaderParams.java
│ │ │ └── RequestParams.java
│ │ │ ├── RequestTasks
│ │ │ ├── BitMapTask.java
│ │ │ ├── JsonObjectTask.java
│ │ │ ├── JsonArrayTask.java
│ │ │ ├── XmlTask.java
│ │ │ └── Task.java
│ │ │ ├── Response.java
│ │ │ └── DownZ.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── downzlibrary
│ │ │ ├── MethodTest.java
│ │ │ ├── ExampleUnitTest.java
│ │ │ ├── DataTypes
│ │ │ ├── TypeTest.java
│ │ │ ├── BitMapTest.java
│ │ │ ├── JsonArrayTest.java
│ │ │ └── JsonObjectTest.java
│ │ │ ├── Parameters
│ │ │ ├── HeaderParamsTest.java
│ │ │ └── RequestParamsTest.java
│ │ │ ├── ListnerInterface
│ │ │ └── HttpListenerTest.java
│ │ │ ├── RequestTasks
│ │ │ ├── BitMapTaskTest.java
│ │ │ ├── JsonArrayTaskTest.java
│ │ │ └── JsonObjectTaskTest.java
│ │ │ ├── Utilities
│ │ │ ├── CacheManagerInterfaceTest.java
│ │ │ └── CacheManagerTest.java
│ │ │ └── ResponseTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── downzlibrary
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── LICENSE
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/downzlibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':downzlibrary'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DownZLibrary
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-hdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-ldpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-ldpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-mdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-hdpi/ic_clear.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-hdpi/ic_close.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_forward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-hdpi/ic_forward.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-hdpi/ic_heart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_reload.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-hdpi/ic_reload.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-ldpi/ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-ldpi/ic_clear.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-ldpi/ic_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-ldpi/ic_close.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-ldpi/ic_forward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-ldpi/ic_forward.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-ldpi/ic_heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-ldpi/ic_heart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-ldpi/ic_reload.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-ldpi/ic_reload.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-mdpi/ic_clear.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-mdpi/ic_close.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_forward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-mdpi/ic_forward.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-mdpi/ic_heart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_reload.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-mdpi/ic_reload.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xhdpi/ic_clear.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xhdpi/ic_close.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xhdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xhdpi/ic_heart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_reload.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xhdpi/ic_reload.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxhdpi/ic_clear.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxhdpi/ic_close.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxhdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxhdpi/ic_heart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxxhdpi/ic_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_forward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xhdpi/ic_forward.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_forward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxhdpi/ic_forward.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_reload.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxhdpi/ic_reload.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_clear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxxhdpi/ic_clear.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxxhdpi/ic_close.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_heart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxxhdpi/ic_heart.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_reload.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxxhdpi/ic_reload.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_backbutton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-hdpi/ic_backbutton.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_backbutton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-mdpi/ic_backbutton.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_backbutton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xhdpi/ic_backbutton.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_backbutton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxhdpi/ic_backbutton.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_forward.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxxhdpi/ic_forward.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_backbutton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/100rabhkr/DownZLibrary/HEAD/app/src/main/res/drawable-xxxhdpi/ic_backbutton.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/MethodTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | /**
6 | * Created by saurabhkumar on 08/08/17.
7 | */
8 | public class MethodTest {
9 |
10 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/saurabhkumar/downz/UserActivityTest.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | /**
6 | * Created by saurabhkumar on 07/08/17.
7 | */
8 | public class UserActivityTest {
9 |
10 |
11 | }
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_in_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Aug 06 04:00:48 IST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/fade_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/slide_in_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/fade_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/hide_to_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_in_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/hide_to_bottom.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_out_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/slide_in_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/rotate.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/slide_out_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/fade_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/rotate.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/fade_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/round_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/round_layout_alternate.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DownZ
3 | Error
4 | http://pastebin.com/raw/wgkJgazE
5 | Load Image
6 | Cancel Load
7 | Remove Image
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/scale_down.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/scale_down.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #00BCD4
7 | #0097A7
8 | #FFC400
9 | #E0E0E0
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/jump_from_down.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
12 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/Utilities/CacheManagerInterface.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.Utilities;
2 |
3 | /**
4 | * Created by saurabhkumar on 06/08/17.
5 | */
6 |
7 | public interface CacheManagerInterface {
8 | public void addDataToCache(String key, T data);
9 |
10 | public void removeDataFromCache(String key);
11 |
12 | public T getDataFromCache(String key);
13 |
14 | public void evictUnused();
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/jump_to_down.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/jump_from_down.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
12 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/res/anim/jump_to_down.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/saurabhkumar/downz/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/DataTypes/TypeTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.DataTypes;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class TypeTest {
11 | @Test
12 | public void setCacheManager() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void setCallback() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void cancel() throws Exception {
23 |
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/DataTypes/BitMapTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.DataTypes;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class BitMapTest {
11 | @Test
12 | public void setCallback() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void cancel() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void setCacheManager() throws Exception {
23 |
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/itemmenu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/DataTypes/Type.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.DataTypes;
2 |
3 | import com.example.downzlibrary.ListnerInterface.HttpListener;
4 | import com.example.downzlibrary.Utilities.CacheManagerInterface;
5 |
6 | /**
7 | * Created by saurabhkumar on 06/08/17.
8 | */
9 |
10 | public abstract class Type {
11 | public abstract Type setCacheManager(CacheManagerInterface cacheManager);
12 |
13 | public abstract Type setCallback(HttpListener callback);
14 |
15 | public abstract boolean cancel();
16 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/DataTypes/JsonArrayTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.DataTypes;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class JsonArrayTest {
11 | @Test
12 | public void setCallback() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void cancel() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void setCacheManager() throws Exception {
23 |
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/DataTypes/JsonObjectTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.DataTypes;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class JsonObjectTest {
11 | @Test
12 | public void setCallback() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void cancel() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void setCacheManager() throws Exception {
23 |
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/ListnerInterface/HttpListener.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.ListnerInterface;
2 |
3 | /**
4 | * Created by saurabhkumar on 06/08/17.
5 | */
6 |
7 | public interface HttpListener {
8 | /**
9 | * callback starts
10 | */
11 | public void onRequest();
12 |
13 | /**
14 | * Callback that's fired after response
15 | *
16 | * @param data of the type T holds the response
17 | */
18 | public void onResponse(T data);
19 |
20 | public void onError();
21 |
22 | public void onCancel();
23 | }
24 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/Parameters/HeaderParamsTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.Parameters;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class HeaderParamsTest {
11 | @Test
12 | public void getKey() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void setKey() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void getValue() throws Exception {
23 |
24 | }
25 |
26 | @Test
27 | public void setValue() throws Exception {
28 |
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/Parameters/RequestParamsTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.Parameters;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class RequestParamsTest {
11 | @Test
12 | public void getKey() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void setKey() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void getValue() throws Exception {
23 |
24 | }
25 |
26 | @Test
27 | public void setValue() throws Exception {
28 |
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/ListnerInterface/HttpListenerTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.ListnerInterface;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class HttpListenerTest {
11 | @Test
12 | public void onRequest() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void onResponse() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void onError() throws Exception {
23 |
24 | }
25 |
26 | @Test
27 | public void onCancel() throws Exception {
28 |
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/RequestTasks/BitMapTaskTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.RequestTasks;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class BitMapTaskTest {
11 | @Test
12 | public void onPreExecute() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void doInBackground() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void onPostExecute() throws Exception {
23 |
24 | }
25 |
26 | @Test
27 | public void onCancelled() throws Exception {
28 |
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/RequestTasks/JsonArrayTaskTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.RequestTasks;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class JsonArrayTaskTest {
11 | @Test
12 | public void onPreExecute() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void doInBackground() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void onPostExecute() throws Exception {
23 |
24 | }
25 |
26 | @Test
27 | public void onCancelled() throws Exception {
28 |
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/RequestTasks/JsonObjectTaskTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.RequestTasks;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class JsonObjectTaskTest {
11 | @Test
12 | public void onPreExecute() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void doInBackground() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void onPostExecute() throws Exception {
23 |
24 | }
25 |
26 | @Test
27 | public void onCancelled() throws Exception {
28 |
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/Parameters/HeaderParams.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.Parameters;
2 |
3 | /**
4 | * Created by saurabhkumar on 06/08/17.
5 | */
6 |
7 | public class HeaderParams {
8 | private String key;
9 | private String value;
10 |
11 | public String getKey() {
12 | return key;
13 | }
14 |
15 | public HeaderParams setKey(String key) {
16 | this.key = key;
17 | return this;
18 | }
19 |
20 | public String getValue() {
21 | return value;
22 | }
23 |
24 | public HeaderParams setValue(String value) {
25 | this.value = value;
26 | return this;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/Parameters/RequestParams.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.Parameters;
2 |
3 | /**
4 | * Created by saurabhkumar on 06/08/17.
5 | */
6 |
7 | public class RequestParams {
8 | private String key;
9 | private String value;
10 |
11 | public String getKey() {
12 | return key;
13 | }
14 |
15 | public RequestParams setKey(String key) {
16 | this.key = key;
17 | return this;
18 | }
19 |
20 | public String getValue() {
21 | return value;
22 | }
23 |
24 | public RequestParams setValue(String value) {
25 | this.value = value;
26 | return this;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/Utilities/CacheManagerInterfaceTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.Utilities;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class CacheManagerInterfaceTest {
11 | @Test
12 | public void addDataToCache() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void removeDataFromCache() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void getDataFromCache() throws Exception {
23 |
24 | }
25 |
26 | @Test
27 | public void evictUnused() throws Exception {
28 |
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/Utilities/CacheManagerTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.Utilities;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class CacheManagerTest {
11 | @Test
12 | public void sizeOf() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void addDataToCache() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void removeDataFromCache() throws Exception {
23 |
24 | }
25 |
26 | @Test
27 | public void getDataFromCache() throws Exception {
28 |
29 | }
30 |
31 | @Test
32 | public void evictUnused() throws Exception {
33 |
34 | }
35 |
36 | }
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/downzlibrary/src/test/java/com/example/downzlibrary/ResponseTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Created by saurabhkumar on 08/08/17.
9 | */
10 | public class ResponseTest {
11 | @Test
12 | public void getCode() throws Exception {
13 |
14 | }
15 |
16 | @Test
17 | public void setCode() throws Exception {
18 |
19 | }
20 |
21 | @Test
22 | public void getData() throws Exception {
23 |
24 | }
25 |
26 | @Test
27 | public void setData() throws Exception {
28 |
29 | }
30 |
31 | @Test
32 | public void getDataAsString() throws Exception {
33 |
34 | }
35 |
36 | @Test
37 | public void getAsBitmap() throws Exception {
38 |
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
19 |
20 |
--------------------------------------------------------------------------------
/downzlibrary/src/androidTest/java/com/example/downzlibrary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.downzlibrary.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/saurabhkumar/downz/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.saurabhkumar.downz", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/saurabhkumar/downz/CustomClasses/ItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz.CustomClasses;
2 |
3 | import android.graphics.Rect;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by saurabhkumar on 07/08/17.
9 | */
10 |
11 | public class ItemDecoration extends RecyclerView.ItemDecoration {
12 | private final int mSpace;
13 |
14 | public ItemDecoration(int space) {
15 | this.mSpace = space;
16 | }
17 |
18 | @Override
19 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
20 | outRect.left = mSpace;
21 | outRect.right = mSpace;
22 | outRect.bottom = mSpace;
23 |
24 | // Add top margin only for the first item to avoid double space between items
25 | if (parent.getChildAdapterPosition(view) == 0)
26 | outRect.top = mSpace;
27 | }
28 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/saurabhkumar/downz/CustomClasses/SpacesItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz.CustomClasses;
2 |
3 | import android.graphics.Rect;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by saurabhkumar on 07/08/17.
9 | */
10 |
11 | public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
12 | private final int mSpace;
13 |
14 | public SpacesItemDecoration(int space) {
15 | this.mSpace = space;
16 | }
17 |
18 | @Override
19 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
20 | outRect.left = mSpace;
21 | outRect.right = mSpace;
22 | outRect.bottom = mSpace;
23 |
24 | // Add top margin only for the first item to avoid double space between items
25 | if (parent.getChildAdapterPosition(view) == 0)
26 | outRect.top = mSpace;
27 | }
28 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/saurabhkumar/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/downzlibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/saurabhkumar/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/downzlibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:26.+'
30 | compile 'com.android.support:recyclerview-v7:26.+'
31 | compile 'de.hdodenhof:circleimageview:2.1.0'
32 | testCompile 'junit:junit:4.12'
33 | }
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Saurabh Kumar
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/saurabhkumar/downz/CustomClasses/MasonryView.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz.CustomClasses;
2 |
3 | import android.provider.ContactsContract;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.widget.ImageView;
7 | import android.widget.ProgressBar;
8 | import android.widget.TextView;
9 |
10 | import com.example.saurabhkumar.downz.R;
11 |
12 | import de.hdodenhof.circleimageview.CircleImageView;
13 |
14 | /**
15 | * Created by saurabhkumar on 07/08/17.
16 | */
17 |
18 | public class MasonryView extends RecyclerView.ViewHolder {
19 |
20 | ImageView Uploadedphoto;
21 | TextView NameOfUser;
22 | TextView UserName;
23 | TextView NumberOfLikes;
24 | de.hdodenhof.circleimageview.CircleImageView ProfileImage;
25 | ProgressBar loading;
26 |
27 |
28 | public MasonryView(View itemView) {
29 | super(itemView);
30 | Uploadedphoto = itemView.findViewById(R.id.uploadedImage);
31 | NameOfUser = itemView.findViewById(R.id.NameOfUser);
32 | UserName = itemView.findViewById(R.id.UserName);
33 | NumberOfLikes = itemView.findViewById(R.id.NumOfLikes);
34 | ProfileImage = itemView.findViewById(R.id.profile_image);
35 | loading = itemView.findViewById(R.id.loadingbar);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.0"
6 | defaultConfig {
7 | applicationId "com.example.saurabhkumar.downz"
8 | minSdkVersion 15
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile project(':downzlibrary')
28 | compile 'com.android.support:appcompat-v7:26.0.0'
29 | compile 'com.android.support:recyclerview-v7:26.0.0'
30 | compile 'com.android.support:design:26.0.0'
31 | compile 'de.hdodenhof:circleimageview:2.1.0'
32 | compile 'uk.co.samuelwall:material-tap-target-prompt:2.0.0'
33 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
34 | testCompile 'junit:junit:4.12'
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
12 |
13 |
21 |
22 |
23 |
24 |
29 |
30 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/RequestTasks/BitMapTask.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.RequestTasks;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.example.downzlibrary.DownZ;
6 | import com.example.downzlibrary.ListnerInterface.HttpListener;
7 | import com.example.downzlibrary.Parameters.HeaderParams;
8 | import com.example.downzlibrary.Parameters.RequestParams;
9 | import com.example.downzlibrary.Response;
10 |
11 | import java.util.ArrayList;
12 |
13 | /**
14 | * Created by saurabhkumar on 06/08/17.
15 | */
16 |
17 | public class BitMapTask extends Task {
18 | private DownZ.Method method;
19 | private String mUrl;
20 | private HttpListener callback;
21 | private boolean error = false;
22 | private ArrayList params;
23 | private ArrayList headers;
24 |
25 | public BitMapTask(DownZ.Method method, String url, ArrayList params, ArrayList headers, HttpListener callback) {
26 | this.mUrl = url;
27 | this.method = method;
28 | this.callback = callback;
29 | this.params = params;
30 | this.headers = headers;
31 | }
32 |
33 | @Override
34 | protected void onPreExecute() {
35 | super.onPreExecute();
36 |
37 | }
38 |
39 | @Override
40 | protected Bitmap doInBackground(String... urls) {
41 | try {
42 | Response response = makeRequest(mUrl, method, params, headers);
43 | Bitmap bitmap = response.getAsBitmap();
44 | if (this.mCacheManager != null) {
45 | if (this.mCacheManager.getDataFromCache(mUrl) == null)
46 | this.mCacheManager.addDataToCache(mUrl, bitmap);
47 | }
48 | return bitmap;
49 |
50 | } catch (Exception e) {
51 | e.printStackTrace();
52 | error = true;
53 | }
54 |
55 | return null;
56 | }
57 |
58 | @Override
59 | protected void onPostExecute(Bitmap data) {
60 | super.onPostExecute(data);
61 | if (!error)
62 | this.callback.onResponse(data);
63 | else
64 | this.callback.onError();
65 | }
66 |
67 | @Override
68 | protected void onCancelled() {
69 | super.onCancelled();
70 | if (this.mCacheManager != null) {
71 | this.mCacheManager.removeDataFromCache(mUrl);
72 | }
73 |
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/Response.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.provider.DocumentsContract;
6 | import android.util.Xml;
7 |
8 | import org.xmlpull.v1.XmlPullParser;
9 | import org.xmlpull.v1.XmlPullParserException;
10 | import org.xmlpull.v1.XmlPullParserFactory;
11 |
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.io.InputStreamReader;
15 | import java.io.Reader;
16 | import java.util.List;
17 |
18 | import javax.xml.parsers.DocumentBuilder;
19 | import javax.xml.parsers.DocumentBuilderFactory;
20 |
21 | import static java.lang.System.in;
22 |
23 | /**
24 | * Created by saurabhkumar on 06/08/17.
25 | */
26 |
27 | public class Response {
28 | private int code;
29 | private InputStream inputStream;
30 |
31 | public int getCode() {
32 | return code;
33 | }
34 |
35 | public Response setCode(int code) {
36 | this.code = code;
37 | return this;
38 | }
39 |
40 | public InputStream getData() {
41 | return inputStream;
42 | }
43 |
44 | public Response setData(InputStream data) {
45 | this.inputStream = data;
46 | return this;
47 | }
48 |
49 | /**
50 | * Reads an InputStream and converts it to a String.
51 | *
52 | * @return String
53 | * @throws IOException
54 | */
55 | public String getDataAsString() throws IOException {
56 | final int bufferSize = 1024;
57 | final char[] buffer = new char[bufferSize];
58 | final StringBuilder out = new StringBuilder();
59 | Reader in = new InputStreamReader(inputStream, "UTF-8");
60 | for (; ; ) {
61 | int i = in.read(buffer, 0, buffer.length);
62 | if (i < 0)
63 | break;
64 | out.append(buffer, 0, i);
65 | }
66 | if (inputStream != null) {
67 | inputStream.close();
68 | }
69 | return out.toString();
70 |
71 | }
72 |
73 | /**
74 | * Converts input Stream to bitmap
75 | *
76 | * @return Bitmap
77 | */
78 | public Bitmap getAsBitmap() {
79 | Bitmap bitmap = BitmapFactory.decodeStream(this.inputStream);
80 | if (inputStream != null) {
81 | try {
82 | inputStream.close();
83 | } catch (IOException e) {
84 | e.printStackTrace();
85 | }
86 | }
87 | return bitmap;
88 | }
89 |
90 | }
91 |
92 |
93 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/RequestTasks/JsonObjectTask.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.RequestTasks;
2 |
3 | import com.example.downzlibrary.DownZ;
4 | import com.example.downzlibrary.ListnerInterface.HttpListener;
5 | import com.example.downzlibrary.Parameters.HeaderParams;
6 | import com.example.downzlibrary.Parameters.RequestParams;
7 | import com.example.downzlibrary.Response;
8 |
9 | import org.json.JSONObject;
10 |
11 | import java.util.ArrayList;
12 |
13 | /**
14 | * Created by saurabhkumar on 06/08/17.
15 | */
16 |
17 | public class JsonObjectTask extends Task {
18 | private DownZ.Method method;
19 | private String mUrl;
20 | private HttpListener callback;
21 | private boolean error = false;
22 | private ArrayList params;
23 | private ArrayList headers;
24 |
25 | public JsonObjectTask(DownZ.Method method, String url, ArrayList params, ArrayList headers, HttpListener callback) {
26 | this.mUrl = url;
27 | this.method = method;
28 | this.callback = callback;
29 | this.params = params;
30 | this.headers = headers;
31 | }
32 |
33 | @Override
34 | protected void onPreExecute() {
35 | super.onPreExecute();
36 | }
37 |
38 | @Override
39 | protected JSONObject doInBackground(String... urls) {
40 | try {
41 | Response response = makeRequest(mUrl, method, params, headers);
42 | JSONObject json = new JSONObject(response.getDataAsString());
43 | if (this.mCacheManager != null) {
44 | if (this.mCacheManager.getDataFromCache(mUrl) == null)
45 | this.mCacheManager.addDataToCache(mUrl, json);
46 | }
47 | return json;
48 |
49 | } catch (Exception e) {
50 | e.printStackTrace();
51 | error = true;
52 | }
53 |
54 | return null;
55 | }
56 |
57 | @Override
58 | protected void onPostExecute(JSONObject data) {
59 | super.onPostExecute(data);
60 | if (!error)
61 | this.callback.onResponse(data);
62 | else
63 | this.callback.onError();
64 | }
65 |
66 | /**
67 | * Sometimes users may cancel at almost end, so lets remove if data is in cache
68 | */
69 | @Override
70 | protected void onCancelled() {
71 | super.onCancelled();
72 | if (this.mCacheManager != null) {
73 | this.mCacheManager.removeDataFromCache(mUrl);
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/RequestTasks/JsonArrayTask.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.RequestTasks;
2 |
3 | import com.example.downzlibrary.DownZ;
4 | import com.example.downzlibrary.ListnerInterface.HttpListener;
5 | import com.example.downzlibrary.Parameters.HeaderParams;
6 | import com.example.downzlibrary.Parameters.RequestParams;
7 | import com.example.downzlibrary.Response;
8 |
9 | import org.json.JSONArray;
10 |
11 | import java.util.ArrayList;
12 |
13 | /**
14 | * Created by saurabhkumar on 06/08/17.
15 | */
16 |
17 | public class JsonArrayTask extends Task {
18 | private DownZ.Method method;
19 | private String mUrl;
20 | private HttpListener callback;
21 | private boolean error = false;
22 | private ArrayList params;
23 | private ArrayList headers;
24 |
25 |
26 | public JsonArrayTask(DownZ.Method method, String url, ArrayList params, ArrayList headers, HttpListener callback) {
27 | this.mUrl = url;
28 | this.method = method;
29 | this.callback = callback;
30 | this.params = params;
31 | this.headers = headers;
32 | }
33 |
34 | @Override
35 | protected void onPreExecute() {
36 | super.onPreExecute();
37 |
38 | }
39 |
40 | @Override
41 | protected JSONArray doInBackground(String... urls) {
42 | try {
43 |
44 | Response response = makeRequest(mUrl, method, params, headers);
45 | JSONArray json = new JSONArray(response.getDataAsString());
46 | if (this.mCacheManager != null) {
47 | if (this.mCacheManager.getDataFromCache(mUrl) == null)
48 | this.mCacheManager.addDataToCache(mUrl, json);
49 | }
50 | return json;
51 |
52 | } catch (Exception e) {
53 | e.printStackTrace();
54 | error = true;
55 | }
56 |
57 | return null;
58 | }
59 |
60 | @Override
61 | protected void onPostExecute(JSONArray data) {
62 | super.onPostExecute(data);
63 | if (!error)
64 | this.callback.onResponse(data);
65 | else
66 | this.callback.onError();
67 | }
68 |
69 | /**
70 | * Sometimes users may cancel at almost end, so lets remove if data is in cache
71 | */
72 | @Override
73 | protected void onCancelled() {
74 | super.onCancelled();
75 | if (this.mCacheManager != null) {
76 | this.mCacheManager.removeDataFromCache(mUrl);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/DataTypes/JsonObject.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.DataTypes;
2 |
3 | import com.example.downzlibrary.DownZ;
4 | import com.example.downzlibrary.ListnerInterface.HttpListener;
5 | import com.example.downzlibrary.Parameters.HeaderParams;
6 | import com.example.downzlibrary.Parameters.RequestParams;
7 | import com.example.downzlibrary.RequestTasks.JsonObjectTask;
8 | import com.example.downzlibrary.Utilities.CacheManagerInterface;
9 |
10 | import org.json.JSONObject;
11 |
12 | import java.util.ArrayList;
13 |
14 | /**
15 | * Created by saurabhkumar on 06/08/17.
16 | */
17 |
18 | public class JsonObject extends Type {
19 | private String url;
20 | private HttpListener mListener;
21 | private DownZ.Method method;
22 | private ArrayList params;
23 | private ArrayList headers;
24 | private JsonObjectTask mTask;
25 | private CacheManagerInterface mCacheManager;
26 |
27 | /**
28 | * Constructor to load json datatyes
29 | */
30 | public JsonObject(DownZ.Method m, String url, ArrayList params, ArrayList headers) {
31 | this.url = url;
32 | this.method = m;
33 | this.headers = headers;
34 | this.params = params;
35 | }
36 |
37 | /**
38 | * Sets future callback
39 | */
40 |
41 | public JsonObject setCallback(HttpListener listener) {
42 | this.mListener = listener;
43 | mListener.onRequest();
44 | JSONObject data;
45 | if (mCacheManager != null) {
46 | data = mCacheManager.getDataFromCache(url);
47 | if (data != null) {
48 | mListener.onResponse(data);
49 | return this;
50 | }
51 | }
52 |
53 | mTask = new JsonObjectTask(method, url, params, headers, mListener);
54 | mTask.execute();
55 | return this;
56 | }
57 |
58 | /**
59 | * Cancels the current request
60 | *
61 | * @return True if cancelled
62 | */
63 | public boolean cancel() {
64 | if (mTask != null) {
65 | mTask.cancel(true);
66 | if (mTask.isCancelled()) {
67 | mListener.onCancel();
68 | return true;
69 | } else {
70 | return false;
71 | }
72 | }
73 |
74 | return false;
75 | }
76 |
77 |
78 | public JsonObject setCacheManager(CacheManagerInterface cache) {
79 | this.mCacheManager = cache;
80 | return this;
81 | }
82 |
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/saurabhkumar/downz/CustomClasses/User.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz.CustomClasses;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * Created by saurabhkumar on 06/08/17.
7 | */
8 |
9 | public class User {
10 |
11 | String Name;
12 | String ProfilePicUrl;
13 | String UploadedImageUrl;
14 | boolean isLikedByUser;
15 | String UserName;
16 | int NumberOfLikes;
17 | List Categories;
18 | String UrlToSend;
19 |
20 | public User() {
21 | /* empty constructor */
22 | }
23 |
24 | public User(String name, String profilePicUrl, String uploadedImageUrl, boolean isLikedByUser, String userName, int numberOfLikes, List categories, String UrltoSend) {
25 | Name = name;
26 | ProfilePicUrl = profilePicUrl;
27 | UploadedImageUrl = uploadedImageUrl;
28 | this.isLikedByUser = isLikedByUser;
29 | UserName = userName;
30 | NumberOfLikes = numberOfLikes;
31 | Categories = categories;
32 | UrlToSend = UrltoSend;
33 |
34 | }
35 |
36 | public String getUrlToSend() {
37 | return UrlToSend;
38 | }
39 |
40 | public void setUrlToSend(String urlToSend) {
41 | UrlToSend = urlToSend;
42 | }
43 |
44 | public String getName() {
45 | return Name;
46 | }
47 |
48 | public void setName(String name) {
49 | Name = name;
50 | }
51 |
52 | public String getProfilePicUrl() {
53 | return ProfilePicUrl;
54 | }
55 |
56 | public void setProfilePicUrl(String profilePicUrl) {
57 | ProfilePicUrl = profilePicUrl;
58 | }
59 |
60 | public String getUploadedImageUrl() {
61 | return UploadedImageUrl;
62 | }
63 |
64 | public void setUploadedImageUrl(String uploadedImageUrl) {
65 | UploadedImageUrl = uploadedImageUrl;
66 | }
67 |
68 | public boolean isLikedByUser() {
69 | return isLikedByUser;
70 | }
71 |
72 | public void setLikedByUser(boolean likedByUser) {
73 | isLikedByUser = likedByUser;
74 | }
75 |
76 | public String getUserName() {
77 | return UserName;
78 | }
79 |
80 | public void setUserName(String userName) {
81 | UserName = userName;
82 | }
83 |
84 | public int getNumberOfLikes() {
85 | return NumberOfLikes;
86 | }
87 |
88 | public void setNumberOfLikes(int numberOfLikes) {
89 | NumberOfLikes = numberOfLikes;
90 | }
91 |
92 | public List getCategories() {
93 | return Categories;
94 | }
95 |
96 | public void setCategories(List categories) {
97 | Categories = categories;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/DataTypes/XmlType.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.DataTypes;
2 |
3 | import android.graphics.Bitmap;
4 | import android.util.Xml;
5 |
6 | import com.example.downzlibrary.DownZ;
7 | import com.example.downzlibrary.ListnerInterface.HttpListener;
8 | import com.example.downzlibrary.Parameters.HeaderParams;
9 | import com.example.downzlibrary.Parameters.RequestParams;
10 | import com.example.downzlibrary.RequestTasks.BitMapTask;
11 | import com.example.downzlibrary.RequestTasks.XmlTask;
12 | import com.example.downzlibrary.Utilities.CacheManagerInterface;
13 |
14 | import org.w3c.dom.Document;
15 |
16 | import java.util.ArrayList;
17 |
18 | /**
19 | * Created by saurabhkumar on 09/08/17.
20 | */
21 |
22 | public class XmlType extends Type {
23 | private String url;
24 | private HttpListener listener;
25 | private DownZ.Method method;
26 | private ArrayList params;
27 | private ArrayList headers;
28 | private XmlTask mTask;
29 | private CacheManagerInterface mCacheManager;
30 |
31 | public XmlType(DownZ.Method m, String url, ArrayList params, ArrayList headers) {
32 | this.url = url;
33 | this.method = m;
34 | this.headers = headers;
35 | this.params = params;
36 | }
37 |
38 | public XmlType setCallback(HttpListener listener) {
39 | this.listener = listener;
40 | this.listener.onRequest();
41 | Document data;
42 | if (mCacheManager != null) {
43 | data = mCacheManager.getDataFromCache(url);
44 | if (data != null) {
45 | this.listener.onResponse(data);
46 | return this;
47 | }
48 | }
49 |
50 | mTask = new XmlTask(method, url, params, headers, this.listener);
51 | mTask.setmCachemanager(mCacheManager);
52 | mTask.execute();
53 | return this;
54 | }
55 |
56 | /**
57 | * Cancels the current request
58 | *
59 | * @return True if cancelled
60 | */
61 | public boolean cancel() {
62 | if (mTask != null) {
63 | mTask.cancel(true);
64 | if (mTask.isCancelled()) {
65 | listener.onCancel();
66 | return true;
67 | } else {
68 | return false;
69 | }
70 | }
71 |
72 | return false;
73 | }
74 |
75 | /**
76 | * Lets depend on abstraction
77 | * Sets CacheManager for this
78 | *
79 | * @param cache
80 | * @return JsonObjectType
81 | */
82 | public XmlType setCacheManager(CacheManagerInterface cache) {
83 | this.mCacheManager = cache;
84 | return this;
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/DataTypes/BitMap.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.DataTypes;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import com.example.downzlibrary.DownZ;
6 | import com.example.downzlibrary.ListnerInterface.HttpListener;
7 | import com.example.downzlibrary.Parameters.HeaderParams;
8 | import com.example.downzlibrary.Parameters.RequestParams;
9 | import com.example.downzlibrary.RequestTasks.BitMapTask;
10 | import com.example.downzlibrary.Utilities.CacheManagerInterface;
11 |
12 | import java.util.ArrayList;
13 |
14 | /**
15 | * Created by saurabhkumar on 06/08/17.
16 | */
17 |
18 | public class BitMap extends Type {
19 | private String url;
20 | private HttpListener listener;
21 | private DownZ.Method method;
22 | private ArrayList params;
23 | private ArrayList headers;
24 | private BitMapTask mTask;
25 | private CacheManagerInterface mCacheManager;
26 |
27 | /**
28 | * Constructor to load json datatypes
29 | */
30 | public BitMap(DownZ.Method m, String url, ArrayList params, ArrayList headers) {
31 | this.url = url;
32 | this.method = m;
33 | this.headers = headers;
34 | this.params = params;
35 | }
36 |
37 | /**
38 | * Sets future callback after Http response is received
39 | *
40 | * @param listener
41 | */
42 | public BitMap setCallback(HttpListener listener) {
43 | this.listener = listener;
44 | this.listener.onRequest();
45 | Bitmap data;
46 | if (mCacheManager != null) {
47 | data = mCacheManager.getDataFromCache(url);
48 | if (data != null) {
49 | this.listener.onResponse(data);
50 | return this;
51 | }
52 | }
53 |
54 | mTask = new BitMapTask(method, url, params, headers, this.listener);
55 | mTask.setmCachemanager(mCacheManager);
56 | mTask.execute();
57 | return this;
58 | }
59 |
60 | /**
61 | * Cancels the current request
62 | *
63 | * @return True if cancelled
64 | */
65 | public boolean cancel() {
66 | if (mTask != null) {
67 | mTask.cancel(true);
68 | if (mTask.isCancelled()) {
69 | listener.onCancel();
70 | return true;
71 | } else {
72 | return false;
73 | }
74 | }
75 |
76 | return false;
77 | }
78 |
79 | /**
80 | * Lets depend on abstraction
81 | * Sets CacheManager for this
82 | *
83 | * @param cache
84 | * @return JsonObjectType
85 | */
86 | public BitMap setCacheManager(CacheManagerInterface cache) {
87 | this.mCacheManager = cache;
88 | return this;
89 | }
90 |
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/DataTypes/JsonArray.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.DataTypes;
2 |
3 | import com.example.downzlibrary.DownZ;
4 | import com.example.downzlibrary.ListnerInterface.HttpListener;
5 | import com.example.downzlibrary.Parameters.HeaderParams;
6 | import com.example.downzlibrary.Parameters.RequestParams;
7 | import com.example.downzlibrary.RequestTasks.JsonArrayTask;
8 | import com.example.downzlibrary.Utilities.CacheManagerInterface;
9 |
10 | import org.json.JSONArray;
11 |
12 | import java.util.ArrayList;
13 |
14 | /**
15 | * Created by saurabhkumar on 06/08/17.
16 | */
17 |
18 | public class JsonArray extends Type {
19 |
20 | private String url;
21 | private HttpListener mListener;
22 | private DownZ.Method method;
23 | private ArrayList params;
24 | private ArrayList headers;
25 | private JsonArrayTask mTask;
26 | private CacheManagerInterface mCacheManager;
27 |
28 | /**
29 | * Constructor to load json datatyes
30 | *
31 | * @param url
32 | * @param params
33 | * @param headers
34 | */
35 | public JsonArray(DownZ.Method m, String url, ArrayList params, ArrayList headers) {
36 | this.url = url;
37 | this.method = m;
38 | this.headers = headers;
39 | this.params = params;
40 | }
41 |
42 | /**
43 | * Sets future callback after Http response is received
44 | *
45 | * @param listener
46 | */
47 | public JsonArray setCallback(HttpListener listener) {
48 | this.mListener = listener;
49 | this.mListener.onRequest();
50 | JSONArray data;
51 | if (mCacheManager != null) {
52 | data = mCacheManager.getDataFromCache(url);
53 | if (data != null) {
54 | mListener.onResponse(data);
55 | return this;
56 | }
57 | }
58 |
59 | mTask = new JsonArrayTask(method, url, params, headers, mListener);
60 | mTask.setmCachemanager(mCacheManager);
61 | mTask.execute();
62 | return this;
63 | }
64 |
65 | /**
66 | * Cancels the current request
67 | *
68 | * @return True if cancelled
69 | */
70 | public boolean cancel() {
71 | if (mTask != null) {
72 | mTask.cancel(true);
73 | if (mTask.isCancelled()) {
74 | mListener.onCancel();
75 | return true;
76 | } else {
77 | return false;
78 | }
79 | }
80 |
81 | return false;
82 | }
83 |
84 | /**
85 | * Lets depend on abstraction
86 | * Sets CacheManager for this
87 | *
88 | * @param cache
89 | * @return JsonObjectType
90 | */
91 | public JsonArray setCacheManager(CacheManagerInterface cache) {
92 | this.mCacheManager = cache;
93 | return this;
94 | }
95 | //// TODO: 06/08/17 add comments
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/RequestTasks/XmlTask.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.RequestTasks;
2 |
3 | import android.util.Xml;
4 |
5 | import com.example.downzlibrary.DownZ;
6 | import com.example.downzlibrary.ListnerInterface.HttpListener;
7 | import com.example.downzlibrary.Parameters.HeaderParams;
8 | import com.example.downzlibrary.Parameters.RequestParams;
9 | import com.example.downzlibrary.Response;
10 |
11 | import org.json.JSONObject;
12 | import org.w3c.dom.Document;
13 | import org.xml.sax.InputSource;
14 |
15 | import java.io.StringReader;
16 | import java.util.ArrayList;
17 |
18 | import javax.xml.parsers.DocumentBuilderFactory;
19 |
20 | /**
21 | * Created by saurabhkumar on 09/08/17.
22 | */
23 |
24 | public class XmlTask extends Task {
25 | private DownZ.Method method;
26 | private String mUrl;
27 | private HttpListener callback;
28 | private boolean error = false;
29 | private ArrayList params;
30 | private ArrayList headers;
31 |
32 | public XmlTask(DownZ.Method method, String url, ArrayList params, ArrayList headers, HttpListener callback) {
33 | this.mUrl = url;
34 | this.method = method;
35 | this.callback = callback;
36 | this.params = params;
37 | this.headers = headers;
38 | }
39 |
40 | @Override
41 | protected void onPreExecute() {
42 | super.onPreExecute();
43 | }
44 |
45 | @Override
46 | protected Document doInBackground(String... urls) {
47 | try {
48 | Response response = makeRequest(mUrl, method, params, headers);
49 | String xmlfile = response.getDataAsString();
50 | Document doc = DocumentBuilderFactory
51 | .newInstance()
52 | .newDocumentBuilder()
53 | .parse(
54 | new InputSource(
55 | new StringReader(xmlfile)
56 | )
57 | );
58 |
59 | if (this.mCacheManager != null) {
60 | if (this.mCacheManager.getDataFromCache(mUrl) == null)
61 | this.mCacheManager.addDataToCache(mUrl, doc);
62 | }
63 | return doc;
64 |
65 | } catch (Exception e) {
66 | e.printStackTrace();
67 | error = true;
68 | }
69 |
70 | return null;
71 | }
72 |
73 | @Override
74 | protected void onPostExecute(Document data) {
75 | super.onPostExecute(data);
76 | if (!error)
77 | this.callback.onResponse(data);
78 | else
79 | this.callback.onError();
80 | }
81 |
82 | /**
83 | * Sometimes users may cancel at almost end, so lets remove if data is in cache
84 | */
85 | @Override
86 | protected void onCancelled() {
87 | super.onCancelled();
88 | if (this.mCacheManager != null) {
89 | this.mCacheManager.removeDataFromCache(mUrl);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/Utilities/CacheManager.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.Utilities;
2 |
3 | import android.graphics.Bitmap;
4 | import android.os.SystemClock;
5 | import android.util.LruCache;
6 |
7 | import org.json.JSONArray;
8 | import org.json.JSONObject;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * Created by saurabhkumar on 06/08/17.
15 | */
16 |
17 | public class CacheManager extends LruCache implements CacheManagerInterface {
18 |
19 | private final int timeout = 10 * 1000 * 60;
20 |
21 | //timestamp to remove unused items after 10 minutes
22 | HashMap cacheHitTimestamp = new HashMap<>();
23 |
24 | /**
25 | * Constructor
26 | *
27 | * @param cacheSize size of the cache in bytes
28 | */
29 |
30 | public CacheManager(int cacheSize) {
31 | super(cacheSize);
32 | }
33 |
34 | @Override
35 | protected int sizeOf(String key, T data) {
36 | // The cache size will be measured in kilobytes rather than
37 | // number of items.
38 | int bytesCount;
39 | if (data instanceof Bitmap) {
40 | bytesCount = ((Bitmap) data).getByteCount();
41 | } else if (data instanceof JSONObject) {
42 | bytesCount = ((JSONObject) data).toString().getBytes().length;
43 | } else {
44 | bytesCount = ((JSONArray) data).toString().getBytes().length;
45 | }
46 |
47 | return bytesCount / 1024;
48 |
49 | }
50 |
51 | /**
52 | * Adds data to memory cache
53 | *
54 | * @param key key to identify cache resource
55 | * @param data Data to be stored in cache
56 | */
57 | @Override
58 | public void addDataToCache(String key, T data) {
59 | if (getDataFromCache(key) == null) {
60 | synchronized (this) {
61 | put(key, data);
62 | cacheHitTimestamp.put(key, SystemClock.uptimeMillis()); //count to 0 when added
63 | }
64 | }
65 | }
66 |
67 |
68 | /**
69 | * Removes data from cache
70 | *
71 | * @param key identifier to resource in cache
72 | */
73 | @Override
74 | public void removeDataFromCache(String key) {
75 | if (getDataFromCache(key) != null) {
76 | synchronized (this) {
77 | remove(key);
78 | }
79 | }
80 | }
81 |
82 | /**
83 | * Gets resource from cache
84 | *
85 | * @param key identifier
86 | * @return resource
87 | */
88 | @Override
89 | public T getDataFromCache(String key) {
90 | synchronized (this) {
91 | cacheHitTimestamp.put(key, SystemClock.uptimeMillis());
92 | evictUnused();
93 | }
94 | return get(key);
95 | }
96 |
97 | /**
98 | * Removes items that are not used
99 | */
100 | @Override
101 | public void evictUnused() {
102 | Map items = snapshot();
103 | for (String key : items.keySet()) {
104 | long cacheTime = cacheHitTimestamp.get(key);
105 | if (cacheTime + timeout < SystemClock.uptimeMillis()) {
106 | remove(key);
107 | }
108 |
109 | }
110 | }
111 |
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/DownZ.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary;
2 |
3 | import android.content.Context;
4 |
5 | import com.example.downzlibrary.DataTypes.BitMap;
6 | import com.example.downzlibrary.DataTypes.JsonArray;
7 | import com.example.downzlibrary.DataTypes.JsonObject;
8 | import com.example.downzlibrary.DataTypes.XmlType;
9 | import com.example.downzlibrary.Parameters.HeaderParams;
10 | import com.example.downzlibrary.Parameters.RequestParams;
11 |
12 | import java.util.ArrayList;
13 |
14 | /**
15 | * Created by saurabhkumar on 06/08/17.
16 | */
17 |
18 | public class DownZ {
19 | private static DownZ instance = null;
20 | private Context context;
21 | private String url;
22 | private Method method;
23 | private ArrayList params = new ArrayList<>();
24 | private ArrayList headers = new ArrayList<>();
25 |
26 | /**
27 | * Constructor
28 | *
29 | * @param c it is the context
30 | */
31 | public DownZ(Context c) {
32 | this.context = c;
33 | }
34 |
35 | public static DownZ from(Context c) {
36 | return getInstance(c);
37 | }
38 |
39 | /**
40 | * Returns singleton instance for network call
41 | *
42 | * @param context it is the context of activity
43 | */
44 | public static DownZ getInstance(Context context) {
45 | if (context == null)
46 | throw new NullPointerException("Error");
47 |
48 |
49 | synchronized (DownZ.class) {
50 | if (instance == null)
51 | instance = new DownZ(context);
52 | }
53 |
54 | return instance;
55 | }
56 |
57 | /**
58 | * Assigns Url to be loaded
59 | *
60 | * @param m, url
61 | * @return instance
62 | */
63 | public DownZ load(Method m, String url) {
64 | this.url = url;
65 | this.method = m;
66 | return this;
67 | }
68 |
69 | /**
70 | * Sets json datatype for request
71 | *
72 | * @return Json Type
73 | */
74 | public JsonObject asJsonObject() {
75 | return new JsonObject(method, url, params, headers);
76 | }
77 |
78 | /**
79 | * Sets json datatype for request
80 | *
81 | * @return Json Array Type
82 | */
83 | public JsonArray asJsonArray() {
84 | return new JsonArray(method, url, params, headers);
85 | }
86 |
87 | /**
88 | * Sets bitmap type for request
89 | *
90 | * @return Bitmap Type
91 | */
92 |
93 | public BitMap asBitmap() {
94 | return new BitMap(method, url, params, headers);
95 | }
96 |
97 | public XmlType asXml() {
98 | return new XmlType(method, url, params, headers);
99 | }
100 |
101 | /**
102 | * Sets request body parameters
103 | *
104 | * @param key Parameter key
105 | * @param value Parameter value
106 | * @return DownZ instance
107 | */
108 |
109 | public DownZ setRequestParameter(String key, String value) {
110 | RequestParams pram = new RequestParams();
111 | pram.setKey(key);
112 | pram.setValue(value);
113 | this.params.add(pram);
114 | return this;
115 | }
116 |
117 | /**
118 | * Sets request header parameters
119 | *
120 | * @param key Parameter key
121 | * @param value Parameter value
122 | * @return DownZ instance
123 | */
124 |
125 | public DownZ setHeaderParameter(String key, String value) {
126 | HeaderParams pram = new HeaderParams();
127 | pram.setKey(key);
128 | pram.setValue(value);
129 | this.headers.add(pram);
130 | return this;
131 | }
132 |
133 |
134 | public static enum Method {
135 | GET,
136 | POST,
137 | PUT,
138 | DELETE
139 | }
140 |
141 |
142 | }
143 |
--------------------------------------------------------------------------------
/downzlibrary/src/main/java/com/example/downzlibrary/RequestTasks/Task.java:
--------------------------------------------------------------------------------
1 | package com.example.downzlibrary.RequestTasks;
2 |
3 | import android.net.Uri;
4 | import android.os.AsyncTask;
5 |
6 | import com.example.downzlibrary.DownZ;
7 | import com.example.downzlibrary.Parameters.HeaderParams;
8 | import com.example.downzlibrary.Parameters.RequestParams;
9 | import com.example.downzlibrary.Response;
10 | import com.example.downzlibrary.Utilities.CacheManagerInterface;
11 |
12 | import java.io.BufferedWriter;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.io.OutputStream;
16 | import java.io.OutputStreamWriter;
17 | import java.net.HttpURLConnection;
18 | import java.net.URL;
19 | import java.util.ArrayList;
20 |
21 | /**
22 | * Created by saurabhkumar on 06/08/17.
23 | */
24 |
25 | public abstract class Task extends AsyncTask {
26 |
27 | static final int READ_TIMEOUT = 10000;
28 | static final int TIMEOUT = 15000;
29 | final String TAG = getClass().getSimpleName();
30 | protected CacheManagerInterface mCacheManager;
31 | HttpURLConnection conn;
32 |
33 | // Given a URL, establishes an HttpUrlConnection and retrieves
34 | // the web page content as a InputStream, which it returns as
35 | // a string.
36 | protected Response makeRequest(String url, DownZ.Method m, ArrayList params, ArrayList headers) throws IOException {
37 | InputStream is = null;
38 | // Only display the first 500 characters of the retrieved
39 | // web page content.
40 |
41 | URL mUrl = new URL(url);
42 | conn = (HttpURLConnection) mUrl.openConnection();
43 | conn.setReadTimeout(READ_TIMEOUT);
44 | conn.setConnectTimeout(TIMEOUT);
45 | /* time in milliseconds */
46 |
47 | switch (m) {
48 | case GET:
49 | conn.setRequestMethod("GET");
50 | break;
51 |
52 | case POST:
53 | conn.setRequestMethod("POST");
54 | break;
55 |
56 | case PUT:
57 | conn.setRequestMethod("PUT");
58 | break;
59 |
60 | case DELETE:
61 | conn.setRequestMethod("DELETE");
62 | break;
63 | }
64 |
65 |
66 | conn.setDoInput(true);
67 | conn.setDoOutput(m != DownZ.Method.GET);
68 |
69 |
70 | //write headers if any
71 | if (headers.size() > 0) {
72 | for (HeaderParams header : headers) {
73 | conn.setRequestProperty(header.getKey(), header.getValue());
74 | }
75 | }
76 |
77 |
78 | Uri.Builder builder = new Uri.Builder();
79 |
80 | //write request parameters
81 | if (params.size() > 0) {
82 | for (RequestParams itm : params) {
83 | builder.appendQueryParameter(itm.getKey(), itm.getValue());
84 | }
85 |
86 | String query = builder.build().getEncodedQuery();
87 |
88 | OutputStream os = conn.getOutputStream();
89 | BufferedWriter writer = new BufferedWriter(
90 | new OutputStreamWriter(os, "UTF-8"));
91 | writer.write(query);
92 | writer.flush();
93 | writer.close();
94 | os.close();
95 | }
96 |
97 |
98 | conn.connect();
99 |
100 |
101 | int response = conn.getResponseCode();
102 | is = conn.getInputStream();
103 |
104 | Response resp = new Response();
105 | resp.setCode(response);
106 | resp.setData(is);
107 | return resp;
108 | }
109 |
110 |
111 | public void setmCachemanager(CacheManagerInterface cachemanager) {
112 | this.mCacheManager = cachemanager;
113 | }
114 |
115 |
116 | }
117 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/masonrylayoutitem.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
29 |
30 |
34 |
35 |
40 |
41 |
42 |
47 |
48 |
54 |
55 |
56 |
57 |
63 |
64 |
67 |
68 |
76 |
77 |
78 |
82 |
83 |
90 |
91 |
98 |
99 |
106 |
107 |
108 |
109 |
110 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/saurabhkumar/downz/CustomClasses/MasonryAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz.CustomClasses;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.graphics.Bitmap;
6 | import android.os.Bundle;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.util.Log;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.ImageView;
13 | import android.widget.ProgressBar;
14 | import android.widget.TextView;
15 |
16 | import com.example.downzlibrary.DownZ;
17 | import com.example.downzlibrary.ListnerInterface.HttpListener;
18 | import com.example.downzlibrary.Utilities.CacheManager;
19 | import com.example.saurabhkumar.downz.R;
20 | import com.example.saurabhkumar.downz.UserActivity;
21 |
22 | import java.util.List;
23 |
24 | /**
25 | * Created by saurabhkumar on 07/08/17.
26 | */
27 |
28 | public class MasonryAdapter extends RecyclerView.Adapter {
29 |
30 | Context context;
31 | List users;
32 | CacheManager bitmapCacheManager;
33 |
34 | public MasonryAdapter(Context context) {
35 | this.context = context;
36 | this.bitmapCacheManager = new CacheManager<>(40 * 1024 * 1024);
37 |
38 | }
39 |
40 | public void setUsers(List items) {
41 | this.users = items;
42 | }
43 |
44 |
45 | public void clear() {
46 | this.users.clear();
47 | notifyDataSetChanged();
48 | }
49 |
50 |
51 | @Override
52 | public MasonryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
53 | View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.masonrylayoutitem, parent, false);
54 | MasonryViewHolder masonryView = new MasonryViewHolder(layoutView);
55 | return masonryView;
56 | }
57 |
58 | @Override
59 | public void onBindViewHolder(final MasonryViewHolder holder, int position) {
60 | final User current = users.get(position);
61 |
62 | if (current == null) {
63 | return;
64 | }
65 | // for Name of User
66 |
67 | holder.NameOfUser.setText(current.getName());
68 |
69 | // for username
70 |
71 | holder.UserName.setText(current.getUserName());
72 |
73 | // for number of likes
74 | String likes = current.getNumberOfLikes() + "";
75 | holder.NumberOfLikes.setText(likes);
76 |
77 | //for uploaded picture
78 |
79 | DownZ
80 | .from(context)
81 | .load(DownZ.Method.GET, current.getUploadedImageUrl())
82 | .asBitmap()
83 | .setCacheManager(bitmapCacheManager)
84 | .setCallback(new HttpListener() {
85 | @Override
86 | public void onRequest() {
87 | holder.loading.setVisibility(View.VISIBLE);
88 | }
89 |
90 | @Override
91 | public void onResponse(Bitmap data) {
92 | if (data != null) {
93 | holder.loading.setVisibility(View.GONE);
94 | holder.Uploadedphoto.setImageBitmap(data);
95 | }
96 |
97 | }
98 |
99 | @Override
100 | public void onError() {
101 | holder.loading.setVisibility(View.GONE);
102 | Log.e(String.valueOf(R.string.TAG), "On Load Error");
103 | }
104 |
105 | @Override
106 | public void onCancel() {
107 | holder.loading.setVisibility(View.GONE);
108 |
109 | }
110 | });
111 |
112 | // for profile picture
113 |
114 | DownZ
115 | .from(context)
116 | .load(DownZ.Method.GET, current.getProfilePicUrl())
117 | .asBitmap()
118 | .setCacheManager(bitmapCacheManager)
119 | .setCallback(new HttpListener() {
120 | @Override
121 | public void onRequest() {
122 | holder.loading.setVisibility(View.VISIBLE);
123 | }
124 |
125 | @Override
126 | public void onResponse(Bitmap data) {
127 | if (data != null) {
128 | holder.loading.setVisibility(View.GONE);
129 | holder.ProfileImage.setImageBitmap(data);
130 | }
131 |
132 | }
133 |
134 | @Override
135 | public void onError() {
136 | holder.loading.setVisibility(View.GONE);
137 | Log.e(String.valueOf(R.string.TAG), "On Load Error");
138 | }
139 |
140 | @Override
141 | public void onCancel() {
142 | holder.loading.setVisibility(View.GONE);
143 |
144 | }
145 | });
146 | //for Onclick listner
147 | holder.mView.setOnClickListener(new View.OnClickListener() {
148 | @Override
149 | public void onClick(View view) {
150 | String NameofUser = current.getName();
151 | String UserName = current.getUserName();
152 | String UploadUrl = current.getUploadedImageUrl();
153 | String ProfilepicUrl = current.getProfilePicUrl();
154 | String NumberofLikes = current.getNumberOfLikes() + "";
155 | String Tags = "Tags: ";
156 | List categories = current.getCategories();
157 | for (int i = 0; i < categories.size(); i++) {
158 | Tags = Tags + categories.get(i) + ", ";
159 | }
160 | Context context = holder.mView.getContext();
161 | Intent intent = new Intent(context, UserActivity.class);
162 | Bundle extras = new Bundle();
163 | extras.putString("Name_Of_User", NameofUser);
164 | extras.putString("User_Name", UserName);
165 | extras.putString("Upload_Url", UploadUrl);
166 | extras.putString("Profile_Pic", ProfilepicUrl);
167 | extras.putString("Categories", Tags);
168 | extras.putString("No_Of_Likes", NumberofLikes);
169 | intent.putExtras(extras);
170 | context.startActivity(intent);
171 | }
172 | });
173 |
174 |
175 | }
176 |
177 | @Override
178 | public int getItemCount() {
179 | return users.size();
180 | }
181 |
182 | public class MasonryViewHolder extends RecyclerView.ViewHolder {
183 | View mView;
184 | ImageView Uploadedphoto;
185 | TextView NameOfUser;
186 | TextView UserName;
187 | TextView NumberOfLikes;
188 | de.hdodenhof.circleimageview.CircleImageView ProfileImage;
189 | ProgressBar loading;
190 |
191 |
192 | public MasonryViewHolder(View itemView) {
193 | super(itemView);
194 | mView = itemView;
195 |
196 |
197 | Uploadedphoto = itemView.findViewById(R.id.uploadedImage);
198 | NameOfUser = itemView.findViewById(R.id.NameOfUser);
199 | UserName = itemView.findViewById(R.id.UserName);
200 | NumberOfLikes = itemView.findViewById(R.id.NumOfLikes);
201 | ProfileImage = itemView.findViewById(R.id.profile_image);
202 | loading = itemView.findViewById(R.id.loadingbar);
203 | }
204 |
205 | }
206 | }
207 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/saurabhkumar/downz/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz;
2 |
3 | import android.content.Intent;
4 | import android.os.Handler;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v4.widget.SwipeRefreshLayout;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.os.Bundle;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.support.v7.widget.StaggeredGridLayoutManager;
11 | import android.support.v7.widget.Toolbar;
12 | import android.widget.RelativeLayout;
13 | import android.widget.Toast;
14 |
15 | import com.example.downzlibrary.DownZ;
16 | import com.example.downzlibrary.ListnerInterface.HttpListener;
17 | import com.example.downzlibrary.Utilities.CacheManager;
18 | import com.example.saurabhkumar.downz.CustomClasses.MasonryAdapter;
19 | import com.example.saurabhkumar.downz.CustomClasses.SpacesItemDecoration;
20 | import com.example.saurabhkumar.downz.CustomClasses.User;
21 |
22 | import org.json.JSONArray;
23 | import org.json.JSONException;
24 | import org.json.JSONObject;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 | public class MainActivity extends AppCompatActivity {
30 |
31 | Toolbar mToolbar;
32 | RecyclerView mRecyclerView;
33 | MasonryAdapter adapter;
34 | CacheManager jsonArrayCacheManager;
35 | String Url;
36 | boolean refresh = false;
37 | StaggeredGridLayoutManager mLayoutmanager;
38 | private SwipeRefreshLayout swipeRefreshLayout;
39 | private Handler handler = new Handler();
40 | private final Runnable refreshing = new Runnable() {
41 | public void run() {
42 | try {
43 | if (isRefreshing()) {
44 | // RE-Run after 1 Second
45 | handler.postDelayed(this, 1000);
46 | } else {
47 | // Stop the animation once we are done fetching data.
48 | swipeRefreshLayout.setRefreshing(false);
49 | /**
50 | * You can add code to update your list with the new data.
51 | **/
52 | }
53 | } catch (Exception e) {
54 | e.printStackTrace();
55 | }
56 | }
57 | };
58 |
59 | @Override
60 | protected void onCreate(Bundle savedInstanceState) {
61 | super.onCreate(savedInstanceState);
62 | setContentView(R.layout.activity_main);
63 | Url = String.valueOf(R.string.URL);
64 | jsonArrayCacheManager = new CacheManager<>(40 * 1024 * 1024); // 40mb
65 | swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
66 | mToolbar = findViewById(R.id.toolbar);
67 |
68 | if (mToolbar != null) {
69 | setSupportActionBar(mToolbar);
70 | getSupportActionBar().setTitle("DownZtrest");
71 | }
72 |
73 | mRecyclerView = (RecyclerView) findViewById(R.id.recyclerViewUser);
74 | mLayoutmanager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
75 | // mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL));
76 | mRecyclerView.setLayoutManager(mLayoutmanager);
77 | //mRecyclerView.setAdapter(adapter);
78 | SpacesItemDecoration decoration = new SpacesItemDecoration(16);
79 | mRecyclerView.addItemDecoration(decoration);
80 | swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
81 | adapter = new MasonryAdapter(this);
82 | populatelayout();
83 |
84 | // Swipe to refresh
85 |
86 | swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
87 | @Override
88 | public void onRefresh() {
89 | Intent intent = new Intent(MainActivity.this, MainActivity.class);
90 | //intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
91 | startActivity(intent);
92 | overridePendingTransition(0, 0);
93 | finish();
94 |
95 | }
96 | });
97 |
98 |
99 | }
100 |
101 | public void populatelayout() {
102 | DownZ
103 | .from(MainActivity.this)
104 | .load(DownZ.Method.GET, "http://pastebin.com/raw/wgkJgazE")
105 | .asJsonArray()
106 | .setCacheManager(jsonArrayCacheManager)
107 | .setCallback(new HttpListener() {
108 | @Override
109 | public void onRequest() {
110 | startSync();
111 |
112 | }
113 |
114 | @Override
115 | public void onResponse(JSONArray data) {
116 |
117 |
118 | if (data != null) {
119 | int lengthofdata = data.length();
120 |
121 | List UserList = new ArrayList();
122 |
123 | for (int i = 0; i <= lengthofdata; i++) {
124 | try {
125 | //Toast.makeText(MainActivity.this,"here",Toast.LENGTH_SHORT).show();
126 | JSONObject jUser = data.getJSONObject(i);
127 | JSONObject ObjectforNames = jUser.getJSONObject("user");
128 | JSONArray CategoryArray = jUser.getJSONArray("categories");
129 | JSONObject ObjectforUrls = jUser.getJSONObject("urls");
130 | JSONObject ObjectforProfilePic = ObjectforNames.getJSONObject("profile_image");
131 | String nameofuser = ObjectforNames.get("name").toString();
132 | String username = "@" + ObjectforNames.get("username").toString();
133 | List categories = new ArrayList();
134 | int lengthofcategories = CategoryArray.length();
135 | for (int j = 0; j <= lengthofcategories; j++) {
136 | try {
137 | JSONObject Category = CategoryArray.getJSONObject(j);
138 | String CategoryName = Category.getString("title");
139 | categories.add(CategoryName);
140 | } catch (JSONException e) {
141 | e.printStackTrace();
142 | }
143 | }
144 | String uploadedphotourl = ObjectforUrls.getString("regular");
145 | String urltosend = ObjectforUrls.getString("full");
146 | String profilepicurl = ObjectforProfilePic.getString("large");
147 | boolean islikedbyuser = jUser.getBoolean("liked_by_user");
148 | int numberOfLikes = jUser.getInt("likes");
149 | User newUser = new User(nameofuser, profilepicurl, uploadedphotourl, islikedbyuser, username, numberOfLikes, categories, urltosend);
150 | UserList.add(newUser);
151 |
152 | } catch (JSONException e) {
153 | e.printStackTrace();
154 | }
155 |
156 | }
157 | adapter.setUsers(UserList);
158 | mRecyclerView.setAdapter(adapter);
159 | Snackbar.make(findViewById(android.R.id.content), "Click on the images to know more", Snackbar.LENGTH_LONG).show();
160 | refresh = false;
161 | }
162 | }
163 |
164 | @Override
165 | public void onError() {
166 | Toast.makeText(MainActivity.this, "error", Toast.LENGTH_SHORT).show();
167 | refresh = false;
168 | }
169 |
170 | @Override
171 | public void onCancel() {
172 | refresh = false;
173 | }
174 | });
175 | }
176 |
177 | public void startSync() {
178 | refresh = true;
179 | if (!swipeRefreshLayout.isRefreshing()) {
180 | swipeRefreshLayout.setRefreshing(true);
181 | }
182 | handler.post(refreshing);
183 | }
184 |
185 | boolean isRefreshing() {
186 | return refresh;
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DownZ
2 | ===================
3 | [](https://jitpack.io/#100rabhkr/DownZLibrary) | [View release history](https://github.com/100rabhkr/DownZLibrary/releases)
4 |
5 | DownZ is an HTTP library that boosts networking in Android apps and makes it significantly easier and faster.
6 |
7 | 
8 |
9 | DownZ offers the following benefits:
10 |
11 | - Handles HTTP requests.
12 | - Transparent memory response caching of JSON and Images with support for request prioritization.
13 | - Cancel a request of image upload or download at any given time.
14 | - Images in memory cache are auto removed if not used for a long time.
15 | - Ease of customization, for example, cancel request and clear cache.
16 | - Strong requisition that makes it easy to effectively manage UI with data being fetched asynchronously from the network.
17 |
18 |
19 | DownZ excels at handling HTTP requests.It comes with built-in support for images, JSON and Xml. By providing built-in support for the features you require, DownZ frees you from writing tons of code and finally allows you to concentrate on the logic that is specific to your app.
20 |
21 |
22 | ----------
23 |
24 |
25 | Download
26 | -------------
27 |
28 |
29 | You can use Gradle
30 |
31 | **Step 1.** Add the JitPack repository to your build file , Add it in your root build.gradle at the end of repositories:
32 |
33 | allprojects {
34 | repositories {
35 | ...
36 | maven { url 'https://jitpack.io' }
37 | }
38 | }
39 |
40 | **Step 2.** Add the dependency
41 |
42 | dependencies {
43 | compile 'com.github.100rabhkr:DownZLibrary:1.1'
44 | }
45 |
46 |
47 | Or Maven:
48 |
49 | **Step 1.** Add the JitPack repository to your build file
50 |
51 |
52 |
53 | jitpack.io
54 | https://jitpack.io
55 |
56 |
57 |
58 | **Step 2.** Add the dependency
59 |
60 |
61 | com.github.100rabhkr
62 | DownZLibrary
63 | 1.1
64 |
65 |
66 | Or Sbt:
67 |
68 | **Step 1.** Add the JitPack repository to your build file Add it in your build.sbt at the end of resolvers:
69 |
70 | resolvers += "jitpack" at "https://jitpack.io"
71 |
72 | **Step 2.** Add the dependency
73 |
74 | libraryDependencies += "com.github.100rabhkr" % "DownZLibrary" % "1.1"
75 |
76 |
77 | Snapshots from Sample App
78 | -------------
79 |
80 |
81 |
82 |
83 |
84 | ----------
85 |
86 | Download Sample App
87 | -------------
88 | All the source code can be downloaded from [Github's Release page](https://github.com/100rabhkr/DownZLibrary/releases)
89 |
90 | You can also download the sample app from [here](https://drive.google.com/open?id=0BwG2nwOU6FIWLW50V2tCYmVZZXpFc2VOQkhQMTZ1bG16cWZr)
91 |
92 |
93 | How do I use DownZ?
94 | -------------------
95 |
96 | **Make Standard Request**
97 |
98 | …
99 | DownZ
100 | .from(mContext) //context
101 | .load(DownZ.Method.GET, “http://yoururl.com”)
102 | .asBitmap() //asJsonArray() or asJsonObject() or asXml() can be used depending on need
103 | .setCallback(new HttpListener() {
104 | @Override
105 | public void onRequest() {
106 |
107 | //On Beginning of request
108 |
109 | }
110 |
111 | @Override
112 | public void onResponse(Bitmap data) {
113 |
114 | if(data != null){
115 |
116 | // do something
117 |
118 | }
119 | }
120 |
121 | @Override
122 | public void onError() {
123 |
124 | //do something when there is an error
125 |
126 | }
127 |
128 | @Override
129 | public void onCancel() {
130 |
131 | //do something when request cancelled
132 |
133 | }
134 | });
135 |
136 | **Pass Header or Request Parameters (Optional)**
137 |
138 |
139 |
140 | ...
141 | DownZ
142 | .from(MainActivity.this)
143 | .load(DownZ.Method.GET,mUrl)
144 | .setHeaderParameter("key","value")
145 | .setRequestParameter("key1","value1")
146 | .setRequestParameter("key2","value2")
147 | .asBitmap()
148 | .setCallback(new HttpListener() {
149 | @Override
150 | public void onRequest() {
151 |
152 | }
153 |
154 | @Override
155 | public void onResponse(Bitmap bitmap) {
156 | if(bitmap != null){
157 |
158 | //do something
159 | }
160 | }
161 |
162 | @Override
163 | public void onError() {
164 |
165 | }
166 |
167 | @Override
168 | public void onCancel() {
169 |
170 | }
171 | });
172 |
173 |
174 | **Enable Cache**
175 |
176 |
177 | ...
178 | public class SomeActivity extends AppCompatActivity {
179 | ...
180 | CacheManager cacheManager; // we can use JSONObject, Bitmap as generic type
181 | @Override
182 | protected void onCreate(Bundle savedInstanceState) {
183 | ...
184 | cacheManager=new CacheManager<>(40*1024*1024); // 40mb
185 | }
186 |
187 | public void OnRequestMade(View v){
188 | DownZ
189 | .from(this)
190 | .load(DownZ.Method.GET, "http://www.url.com")
191 | .asJsonArray()
192 | .setCacheManager(cacheManager)
193 | .setCallback(new HttpListener() {
194 | @Override
195 | public void onRequest() {
196 | //fired when request begins
197 | }
198 |
199 | @Override
200 | public void onResponse(JSONArray data) {
201 | if(data!=null){
202 | // do some stuff here
203 | }
204 | }
205 |
206 | @Override
207 | public void onError() {
208 |
209 | }
210 |
211 | @Override
212 | public void onCancel() {
213 |
214 | }
215 | });
216 | }
217 | }
218 |
219 |
220 | **Load Image into ImageView**
221 |
222 |
223 | ...
224 | public class SomeActivity extends AppCompatActivity {
225 | ...
226 | CacheManager cacheManager;
227 | @Override
228 | protected void onCreate(Bundle savedInstanceState) {
229 | ...
230 | cacheManager=new CacheManager<>(40*1024*1024); // 40mb
231 | imageview = (ImageView) findViewById(R.id.image_profile);
232 | imageview.setDrawingCacheEnabled(true); //can be used if Image has to be shared afterwards
233 | imageview.buildDrawingCache();
234 | ...
235 |
236 | }
237 | //event to make request
238 | public void btnLoadImageClicked(View v){
239 | DownZ
240 | .from(this)
241 | .load(DownZ.Method.GET, "http://www.url.com/image.jpg")
242 | .asBitmap()
243 | .setCacheManager(cacheManager)
244 | .setCallback(new HttpListener() {
245 | @Override
246 | public void onRequest() {
247 | //fired when request begin
248 |
249 |
250 | }
251 |
252 | @Override
253 | public void onResponse(Bitmap data) {
254 | if(data!=null){
255 | // do some stuff here
256 | imageview.setImageBitmap(data);
257 | }
258 | }
259 |
260 | @Override
261 | public void onError() {
262 |
263 | }
264 |
265 | @Override
266 | public void onCancel() {
267 |
268 | }
269 | });
270 | }
271 |
272 | }
273 |
274 | **Removing from Cache**
275 |
276 | ...
277 | public class SomeActivity extends AppCompatActivity {
278 | ...
279 | CacheManager cacheManager;
280 | @Override
281 | protected void onCreate(Bundle savedInstanceState) {
282 | ...
283 | String mUrl = "http://yoururl.com/image.png";
284 | cacheManager=new CacheManager<>(40*1024*1024); // 40mb
285 | imageview = (ImageView) findViewById(R.id.image_profile);
286 | imageview.setDrawingCacheEnabled(true); //can be used if Image has to be shared afterwards
287 | imageview.buildDrawingCache();
288 | ...
289 |
290 | }
291 | //event to clear item from cache
292 | public void btntoClearCache(View v){
293 |
294 | cacheManager.removeDataFromCache(mUrl);
295 | }
296 | }
297 |
298 |
299 | Getting Help
300 | ------------
301 |
302 | To report a specific problem or feature request in DownZ, you can [open a new issue on Github](https://github.com/100rabhkr/DownZLibrary/issues/new). For questions, suggestions, or even to say 'hi', just drop an email at skkumar.sk94@gmail.com
303 |
304 | Contributing
305 | ------------
306 |
307 | If you like DownZ, please contribute by writing at skkumar.sk94@gmail.com. Your help and support would make DownZ even better. Before submitting pull requests, contributors must sign [Google's individual contributor license agreement.](https://cla.developers.google.com/about/google-individual)
308 |
309 | Author
310 | ------
311 |
312 | Saurabh Kumar - [@100rabhkr](https://github.com/100rabhkr) on GitHub, [@NotSaurabhKumar](https://twitter.com/NotSaurabhKumar) on Twitter
313 |
314 | License
315 | -------
316 |
317 | MIT See the [LICENSE](https://github.com/100rabhkr/DownZLibrary/blob/master/LICENSE) file for details.
318 |
319 | Disclaimer
320 | ----------
321 |
322 | This is not an official Google product.
323 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_user.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
19 |
20 |
25 |
26 |
34 |
35 |
41 |
42 |
50 |
51 |
55 |
56 |
61 |
62 |
63 |
68 |
69 |
75 |
76 |
77 |
78 |
79 |
80 |
85 |
86 |
90 |
91 |
98 |
99 |
100 |
101 |
105 |
106 |
112 |
113 |
121 |
122 |
128 |
129 |
130 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
149 |
150 |
159 |
160 |
164 |
165 |
178 |
179 |
182 |
183 |
190 |
191 |
192 |
193 |
197 |
198 |
211 |
212 |
215 |
216 |
223 |
224 |
225 |
226 |
230 |
231 |
244 |
245 |
248 |
249 |
256 |
257 |
258 |
259 |
260 |
261 |
273 |
274 |
275 |
276 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/saurabhkumar/downz/UserActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.saurabhkumar.downz;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.graphics.drawable.BitmapDrawable;
9 | import android.graphics.drawable.Drawable;
10 | import android.net.Uri;
11 | import android.os.Build;
12 | import android.os.Environment;
13 | import android.provider.MediaStore;
14 | import android.support.design.widget.FloatingActionButton;
15 | import android.support.design.widget.Snackbar;
16 | import android.support.v4.app.ActivityCompat;
17 | import android.support.v4.content.ContextCompat;
18 | import android.support.v7.app.AppCompatActivity;
19 | import android.os.Bundle;
20 | import android.support.v7.widget.Toolbar;
21 | import android.view.Menu;
22 | import android.view.MenuItem;
23 | import android.view.View;
24 | import android.view.WindowManager;
25 | import android.view.animation.Animation;
26 | import android.view.animation.AnimationUtils;
27 | import android.widget.ImageView;
28 | import android.widget.LinearLayout;
29 | import android.widget.ProgressBar;
30 | import android.widget.RelativeLayout;
31 | import android.widget.TextView;
32 |
33 | import com.example.downzlibrary.DataTypes.BitMap;
34 | import com.example.downzlibrary.DataTypes.Type;
35 | import com.example.downzlibrary.DownZ;
36 | import com.example.downzlibrary.ListnerInterface.HttpListener;
37 | import com.example.downzlibrary.Utilities.CacheManager;
38 |
39 | import java.io.File;
40 | import java.io.FileOutputStream;
41 | import java.io.OutputStream;
42 |
43 | import static android.R.attr.bitmap;
44 |
45 | public class UserActivity extends AppCompatActivity {
46 | Toolbar mToolbar;
47 | String UrlforUpload;
48 | String UrlforProfilepic;
49 | String NameofUser;
50 | String UserName;
51 | String Categories;
52 | String NumberOfLikes;
53 | ImageView UploadedImage;
54 | de.hdodenhof.circleimageview.CircleImageView ProfilePic;
55 | TextView NumberofLikesTextView;
56 | TextView Tags;
57 | TextView NameofUserTextView;
58 | TextView UserNameTextView;
59 | int ImageLoadflag;
60 | Type Upload;
61 | BitMap bitmaptosend;
62 | BitMap ProfilePicBitmap;
63 | CacheManager bitmapCacheManager;
64 | ProgressBar progressBar;
65 | int fabFlag;
66 | LinearLayout FabLayout;
67 | FloatingActionButton MainButton;
68 | RelativeLayout Overlay;
69 | Animation animforoverlay;
70 | Animation animforoverlayGone;
71 | Animation animforVisible;
72 | Animation animforFabRotate;
73 | Animation animforInvisible;
74 | Boolean canSend;
75 |
76 |
77 | @Override
78 | protected void onCreate(Bundle savedInstanceState) {
79 | super.onCreate(savedInstanceState);
80 | setContentView(R.layout.activity_user);
81 | mToolbar = findViewById(R.id.toolbar);
82 | this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
83 |
84 | if (mToolbar != null) {
85 | setSupportActionBar(mToolbar);
86 | getSupportActionBar().setTitle("");
87 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
88 | }
89 | /* To get all the values from previous activity */
90 |
91 | Bundle extras = getIntent().getExtras();
92 | UrlforUpload = extras.getString("Upload_Url");
93 | UrlforProfilepic = extras.getString("Profile_Pic");
94 | NameofUser = "by " + extras.getString("Name_Of_User");
95 | UserName = extras.getString("User_Name");
96 | Categories = extras.getString("Categories");
97 | NumberOfLikes = extras.getString("No_Of_Likes");
98 | bitmapCacheManager = new CacheManager<>(40 * 1024 * 1024);
99 | /* Setting Up Layout */
100 | UploadedImage = findViewById(R.id.Upload);
101 | UploadedImage.setDrawingCacheEnabled(true);
102 | UploadedImage.buildDrawingCache();
103 | ProfilePic = findViewById(R.id.profile_image);
104 | Tags = findViewById(R.id.Tags);
105 | NumberofLikesTextView = findViewById(R.id.NumOfLikes);
106 | UserNameTextView = findViewById(R.id.UserNameinNew);
107 | NameofUserTextView = findViewById(R.id.NameOfUserinNew);
108 | progressBar = (ProgressBar) findViewById(R.id.progress);
109 | canSend = false;
110 | // layout containing all FAB buttons
111 |
112 | FabLayout = findViewById(R.id.OptionsLayout);
113 | MainButton = findViewById(R.id.editImage);
114 | Overlay = findViewById(R.id.overlay);
115 | FloatingActionButton Loadimage = findViewById(R.id.LoadImage);
116 | FloatingActionButton CancelLoad = findViewById(R.id.cancelLoad);
117 | FloatingActionButton RemoveImage = findViewById(R.id.clearImage);
118 |
119 | //Setting Visiblity
120 | FabLayout.setVisibility(View.GONE);
121 | MainButton.setImageResource(R.drawable.ic_edit);
122 | Overlay.setVisibility(View.GONE);
123 |
124 | //Setting up animation
125 | animforoverlay = AnimationUtils.loadAnimation(UserActivity.this,
126 | R.anim.fade_in);
127 | animforoverlayGone = AnimationUtils.loadAnimation(UserActivity.this,
128 | R.anim.fade_out);
129 | animforVisible = AnimationUtils.loadAnimation(UserActivity.this,
130 | R.anim.slide_in_right);
131 | animforInvisible = AnimationUtils.loadAnimation(UserActivity.this,
132 | R.anim.slide_out_left);
133 | animforFabRotate = AnimationUtils.loadAnimation(UserActivity.this,
134 | R.anim.rotate);
135 | //Setting Up Content
136 | Tags.setText(Categories);
137 | NameofUserTextView.setText(NameofUser);
138 | UserNameTextView.setText(UserName);
139 | NumberofLikesTextView.setText(NumberOfLikes);
140 |
141 | //Loading Uploaded Image
142 | ImageLoadFunction();
143 |
144 | //Loading Profile Picture
145 |
146 | ProfilePicBitmap = DownZ
147 | .from(UserActivity.this)
148 | .load(DownZ.Method.GET, UrlforProfilepic)
149 | .asBitmap()
150 | .setCacheManager(bitmapCacheManager)
151 | .setCallback(new HttpListener() {
152 | @Override
153 | public void onRequest() {
154 |
155 | }
156 |
157 | @Override
158 | public void onResponse(Bitmap data) {
159 | ProfilePic.setImageBitmap(data);
160 | }
161 |
162 | @Override
163 | public void onError() {
164 |
165 | }
166 |
167 | @Override
168 | public void onCancel() {
169 |
170 | }
171 | });
172 | MainButton.setOnClickListener(new View.OnClickListener() {
173 | @Override
174 | public void onClick(View view) {
175 | if (fabFlag == 0) {
176 | DisplayFab();
177 | } else {
178 | RemoveFab();
179 | }
180 | }
181 | });
182 | Loadimage.setOnClickListener(new View.OnClickListener() {
183 | @Override
184 | public void onClick(View view) {
185 | if (ImageLoadflag != 1) {
186 | ImageLoadFunction();
187 | } else {
188 | Snackbar.make(findViewById(android.R.id.content), "Image Already Exists", Snackbar.LENGTH_SHORT).show();
189 | }
190 | }
191 | });
192 | CancelLoad.setOnClickListener(new View.OnClickListener() {
193 | @Override
194 | public void onClick(View view) {
195 | if (Upload != null) {
196 | Upload.cancel();
197 | Snackbar.make(findViewById(android.R.id.content), "Cancelled", Snackbar.LENGTH_SHORT).show();
198 | }
199 | }
200 | });
201 | RemoveImage.setOnClickListener(new View.OnClickListener() {
202 | @Override
203 | public void onClick(View view) {
204 | ImageLoadflag = 0;
205 | UploadedImage.setImageResource(0);
206 | }
207 | });
208 |
209 |
210 | }
211 |
212 | public void ImageLoadFunction() {
213 | ImageLoadflag = 1;
214 | Upload = DownZ
215 | .from(UserActivity.this)
216 | .load(DownZ.Method.GET, UrlforUpload)
217 | .asBitmap()
218 | .setCacheManager(bitmapCacheManager)
219 | .setCallback(new HttpListener() {
220 | @Override
221 | public void onRequest() {
222 | progressBar.setVisibility(View.VISIBLE);
223 | }
224 |
225 | @Override
226 | public void onResponse(Bitmap data) {
227 | progressBar.setVisibility(View.GONE);
228 | UploadedImage.setImageBitmap(data);
229 | }
230 |
231 | @Override
232 | public void onError() {
233 |
234 | }
235 |
236 | @Override
237 | public void onCancel() {
238 |
239 | }
240 | });
241 |
242 |
243 | }
244 |
245 | public void DisplayFab() {
246 | /*function to show Fab Buttons*/
247 | fabFlag = 1;
248 | FabLayout.setVisibility(View.VISIBLE);
249 | FabLayout.startAnimation(animforVisible);
250 | Overlay.setVisibility(View.VISIBLE);
251 | Overlay.startAnimation(animforoverlay);
252 | MainButton.startAnimation(animforFabRotate);
253 | MainButton.setImageResource(R.drawable.ic_close);
254 |
255 | }
256 |
257 | public void RemoveFab() {
258 | /*function to remove Fab Buttons*/
259 | fabFlag = 0;
260 | FabLayout.setVisibility(View.GONE);
261 | FabLayout.startAnimation(animforInvisible);
262 | Overlay.setVisibility(View.GONE);
263 | Overlay.startAnimation(animforoverlayGone);
264 | MainButton.startAnimation(animforFabRotate);
265 | MainButton.setImageResource(R.drawable.ic_edit);
266 | }
267 |
268 | @Override
269 | public boolean onCreateOptionsMenu(Menu menu) {
270 | // Inflate the menu; this adds items to the action bar if it is present.
271 | getMenuInflater().inflate(R.menu.itemmenu, menu);
272 | return true;
273 | }
274 |
275 | @Override
276 | public boolean onOptionsItemSelected(MenuItem item) {
277 | // Performs function associated with a menu items
278 | switch (item.getItemId()) {
279 | case R.id.action_send:
280 | if (ImageLoadflag == 1) {
281 | Bitmap sendbitmap = UploadedImage.getDrawingCache();
282 | int MyVersion = Build.VERSION.SDK_INT;
283 | if (MyVersion > Build.VERSION_CODES.LOLLIPOP_MR1) {
284 | if (!checkIfAlreadyhavePermission()) {
285 | requestForSpecificPermission();
286 | }
287 |
288 | }
289 | if (canSend) {
290 | // Stores the file so that it can be shared on various apps
291 | String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), sendbitmap, "title", null);
292 | Uri bitmapUri = Uri.parse(bitmapPath);
293 | Intent intent = new Intent(Intent.ACTION_SEND);
294 | intent.setType("image/png");
295 | intent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
296 | startActivity(Intent.createChooser(intent, "Share"));
297 | }
298 |
299 | }
300 |
301 | break;
302 | case R.id.action_download:
303 | Intent i = new Intent(Intent.ACTION_VIEW);
304 | i.setData(Uri.parse(UrlforUpload));
305 | startActivity(i);
306 | break;
307 | }
308 | return super.onOptionsItemSelected(item);
309 | }
310 |
311 | private boolean checkIfAlreadyhavePermission() {
312 | int result = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
313 | if (result == PackageManager.PERMISSION_GRANTED) {
314 | canSend = true;
315 | return true;
316 |
317 | } else {
318 | canSend = false;
319 | return false;
320 | }
321 | }
322 |
323 | private void requestForSpecificPermission() {
324 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
325 | }
326 |
327 | @Override
328 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
329 | switch (requestCode) {
330 | case 101:
331 | if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
332 | //granted
333 | canSend = true;
334 | } else {
335 | canSend = false;
336 | //not granted
337 | }
338 | break;
339 |
340 | default:
341 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
342 | }
343 | }
344 | }
345 |
346 |
--------------------------------------------------------------------------------