├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── healthicon-web.png
│ │ ├── sportsicon-web.png
│ │ ├── worldicon-web.png
│ │ ├── scienceicon-web.png
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── comic.jpeg
│ │ │ │ ├── sports.png
│ │ │ │ ├── world.png
│ │ │ │ ├── politics.png
│ │ │ │ ├── science.png
│ │ │ │ ├── entertainment.png
│ │ │ │ ├── healthormedical.png
│ │ │ │ ├── side_nav_bar.xml
│ │ │ │ ├── ic_menu_send.xml
│ │ │ │ ├── round_textview.xml
│ │ │ │ ├── ic_home.xml
│ │ │ │ ├── ic_menu_slideshow.xml
│ │ │ │ ├── ic_menu_gallery.xml
│ │ │ │ ├── ic_menu_manage.xml
│ │ │ │ ├── ic_menu_camera.xml
│ │ │ │ ├── ic_menu_share.xml
│ │ │ │ └── ic_language_black_24dp.xml
│ │ │ ├── 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
│ │ │ ├── values
│ │ │ │ ├── attrs.xml
│ │ │ │ ├── arrays.xml
│ │ │ │ ├── drawables.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-v14
│ │ │ │ └── dimens.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_friends.xml
│ │ │ │ ├── flipper.xml
│ │ │ │ ├── fragment_main.xml
│ │ │ │ ├── app_bar_main.xml
│ │ │ │ ├── friends_info.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── nav_header_main.xml
│ │ │ │ ├── fragment_blank.xml
│ │ │ │ ├── item.xml
│ │ │ │ ├── friends_merge_page.xml
│ │ │ │ └── layout_demo.xml
│ │ │ ├── menu
│ │ │ │ ├── main.xml
│ │ │ │ ├── menu_news_tabbed.xml
│ │ │ │ └── activity_main_drawer.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── anim
│ │ │ │ └── flipy.xml
│ │ ├── entertainmenticon-web.png
│ │ ├── ic_launcherpolitics-web.png
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hemant
│ │ │ │ └── myfeed
│ │ │ │ ├── Util
│ │ │ │ ├── CustomItemClickListener.java
│ │ │ │ ├── Utils.java
│ │ │ │ └── RVAdapter.java
│ │ │ │ ├── model
│ │ │ │ ├── StringObject.java
│ │ │ │ └── Topic.java
│ │ │ │ ├── yalantis
│ │ │ │ └── flipviewpager
│ │ │ │ │ ├── utils
│ │ │ │ │ └── FlipSettings.java
│ │ │ │ │ ├── adapter
│ │ │ │ │ └── BaseFlipAdapter.java
│ │ │ │ │ └── view
│ │ │ │ │ └── FlipViewPager.java
│ │ │ │ ├── views
│ │ │ │ └── ZoomOutPageTransformer.java
│ │ │ │ ├── AppClass.java
│ │ │ │ ├── fragments
│ │ │ │ ├── BlankFragment.java
│ │ │ │ └── MainFragment.java
│ │ │ │ └── Activities
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── hemant
│ │ │ └── myfeed
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── hemant
│ │ └── myfeed
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── google-services.json
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
├── codeStyles
│ └── Project.xml
└── misc.xml
├── Screenshot_2016-11-08-12-03-12.jpg
├── Screenshot_2016-11-08-12-04-02.jpg
├── Screenshot_2016-11-08-12-04-53.jpg
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/healthicon-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/healthicon-web.png
--------------------------------------------------------------------------------
/app/src/main/sportsicon-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/sportsicon-web.png
--------------------------------------------------------------------------------
/app/src/main/worldicon-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/worldicon-web.png
--------------------------------------------------------------------------------
/app/src/main/scienceicon-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/scienceicon-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/Screenshot_2016-11-08-12-03-12.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/Screenshot_2016-11-08-12-03-12.jpg
--------------------------------------------------------------------------------
/Screenshot_2016-11-08-12-04-02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/Screenshot_2016-11-08-12-04-02.jpg
--------------------------------------------------------------------------------
/Screenshot_2016-11-08-12-04-53.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/Screenshot_2016-11-08-12-04-53.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/comic.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/drawable/comic.jpeg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sports.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/drawable/sports.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/world.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/drawable/world.png
--------------------------------------------------------------------------------
/app/src/main/entertainmenticon-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/entertainmenticon-web.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/politics.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/drawable/politics.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/science.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/drawable/science.png
--------------------------------------------------------------------------------
/app/src/main/ic_launcherpolitics-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/ic_launcherpolitics-web.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/entertainment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/drawable/entertainment.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/healthormedical.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/drawable/healthormedical.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hemant3370/NEWS/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/Util/CustomItemClickListener.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.Util;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by anuraggupta on 31/01/16.
7 | */
8 | public interface CustomItemClickListener {
9 | void onItemClick(View v, int position);
10 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/Util/Utils.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.Util;
2 |
3 |
4 |
5 | import android.os.Build;
6 |
7 | public class Utils {
8 |
9 |
10 | public static boolean isLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
11 |
12 |
13 |
14 |
15 |
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon May 14 00:47:18 IST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | org.gradle.jvmargs=-Xmx1536M
7 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/arrays.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | - @color/indicator_1
5 | - @color/indicator_2
6 | - @color/indicator_3
7 | - @color/indicator_4
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v14/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 | 0dp
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_friends.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/side_nav_bar.xml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_send.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/hemant/myfeed/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hemant.news;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # newsApp
2 |
3 | [NEWS Android App](https://play.google.com/store/apps/details?id=com.hemant.myfeed) [](https://play.google.com/store/apps/details?id=com.hemant.myfeed)
4 |
5 | 

6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/round_textview.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_home.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/hemant/myfeed/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hemant.news;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/anim/flipy.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_news_tabbed.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_slideshow.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_gallery.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_manage.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/flipper.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/model/StringObject.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.model;
2 | import io.realm.Realm;
3 | import io.realm.RealmObject;
4 | import io.realm.annotations.RealmClass;
5 |
6 | @RealmClass
7 | public class StringObject extends RealmObject {
8 | public String string;
9 |
10 | public StringObject() {
11 |
12 | }
13 |
14 | public static StringObject init(Realm realm, String str) {
15 | StringObject stringObject = realm.createObject(StringObject.class);
16 | stringObject.string = str;
17 | return stringObject;
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 | - @android:drawable/ic_menu_camera
3 | - @android:drawable/ic_menu_gallery
4 | - @android:drawable/ic_menu_slideshow
5 | - @android:drawable/ic_menu_manage
6 | - @android:drawable/ic_menu_share
7 | - @android:drawable/ic_menu_send
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_camera.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_main_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
21 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_share.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 160dp
5 |
6 | 4dp
7 | 2dp
8 | 16dp
9 | 8dp
10 |
11 |
15 | 8dp
16 | 110dp
17 | 18sp
18 |
19 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | org.gradle.jvmargs=-Xmx1536M
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NEWS
3 |
4 | Open navigation drawer
5 | Close navigation drawer
6 |
7 | Settings
8 |
9 |
10 | Hello blank fragment
11 | Full Article
12 | Hello World from section: %1$d
13 | NewsTabbedActivity
14 | EXAMPLE
15 | Add widget
16 | Home
17 | Rate
18 | About
19 | NEWS
20 | By Hemant Singh
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #F4B63E
7 | #EB6460
8 | #10b4a5
9 | #088A85
10 | #7c57e4
11 | #ff4284
12 | #ff8c6a
13 | #ffffff
14 | #000000
15 | #99444444
16 | #616161
17 | #9e9e9e
18 | #5d4037
19 |
20 | #55B3C2
21 | #64A4A4
22 | #66D7B9
23 | #FDBC7D
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/app_bar_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/yalantis/flipviewpager/utils/FlipSettings.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.yalantis.flipviewpager.utils;
2 |
3 | import java.util.HashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * @author Yalantis
8 | */
9 | public class FlipSettings {
10 | private int defaultPage;
11 |
12 | private Map pages = new HashMap<>();
13 |
14 | private FlipSettings(int defaultPage) {
15 | this.defaultPage = defaultPage;
16 | }
17 |
18 | public void savePageState(int position, int page) {
19 | pages.put(position, page);
20 | }
21 |
22 | public Integer getPageForPosition(int position) {
23 | return pages.containsKey(position) ? pages.get(position) : defaultPage;
24 | }
25 |
26 | public int getDefaultPage() {
27 | return defaultPage;
28 | }
29 |
30 | public static class Builder {
31 |
32 | private int defaultPage = 1;
33 |
34 | public Builder defaultPage(int page) {
35 | this.defaultPage = page;
36 | return this;
37 | }
38 |
39 | public FlipSettings build() {
40 | return new FlipSettings(defaultPage);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_language_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/friends_info.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
11 |
14 |
15 |
18 |
19 |
22 |
23 |
27 |
30 |
33 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
19 |
20 |
21 |
22 |
26 |
27 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
27 |
28 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_blank.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
21 |
22 |
23 |
33 |
34 |
--------------------------------------------------------------------------------
/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/anuraggupta/Anuj/android-sdk-mac_x86/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 | # Keep Picasso
19 | -keep class com.squareup.picasso.** { *; }
20 | -keepclasseswithmembers class * {
21 | @com.squareup.picasso.** *;
22 | }
23 | -keepclassmembers class * {
24 | @com.squareup.picasso.** *;
25 | }
26 | -dontwarn com.squareup.picasso.**
27 | -keepclasseswithmembernames class * {
28 | native ;
29 | }
30 | -keep class butterknife.** { *; }
31 | -dontwarn butterknife.internal.**
32 | -keep class **$$ViewBinder { *; }
33 |
34 | -keepclasseswithmembernames class * {
35 | @butterknife.* ;
36 | }
37 |
38 | -keepclasseswithmembernames class * {
39 | @butterknife.* ;
40 | }
41 |
42 |
43 | -dontskipnonpubliclibraryclassmembers
44 |
45 | -keepattributes *Annotation*,EnclosingMethod
46 |
47 | -keepnames class org.codehaus.jackson.** { *; }
48 |
49 | -dontwarn javax.xml.**
50 | -dontwarn javax.xml.stream.events.**
51 | -dontwarn com.fasterxml.jackson.databind.**
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "74069040601",
4 | "firebase_url": "https://knowfeed.firebaseio.com",
5 | "project_id": "project-2279518085934155414",
6 | "storage_bucket": "project-2279518085934155414.appspot.com"
7 | },
8 | "client": [
9 | {
10 | "client_info": {
11 | "mobilesdk_app_id": "1:74069040601:android:eb7517fa59150825",
12 | "android_client_info": {
13 | "package_name": "com.hemant.myfeed"
14 | }
15 | },
16 | "oauth_client": [
17 | {
18 | "client_id": "74069040601-5bqt6d6u8narcc5308rqltb1v5n56dp6.apps.googleusercontent.com",
19 | "client_type": 1,
20 | "android_info": {
21 | "package_name": "com.hemant.myfeed",
22 | "certificate_hash": "3D000EA5D8ACF018B9D267FB454D4A54E1C2D8FD"
23 | }
24 | },
25 | {
26 | "client_id": "74069040601-0ui1kmna2j3813h2k7mvs8sa7sdtvlv8.apps.googleusercontent.com",
27 | "client_type": 3
28 | }
29 | ],
30 | "api_key": [
31 | {
32 | "current_key": "AIzaSyDuYH_ujebCcpzBb-G-hxyZez3uqbjO6QI"
33 | }
34 | ],
35 | "services": {
36 | "analytics_service": {
37 | "status": 1
38 | },
39 | "appinvite_service": {
40 | "status": 2,
41 | "other_platform_oauth_client": [
42 | {
43 | "client_id": "74069040601-0ui1kmna2j3813h2k7mvs8sa7sdtvlv8.apps.googleusercontent.com",
44 | "client_type": 3
45 | }
46 | ]
47 | },
48 | "ads_service": {
49 | "status": 2
50 | }
51 | }
52 | }
53 | ],
54 | "configuration_version": "1"
55 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
20 |
27 |
28 |
37 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/views/ZoomOutPageTransformer.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.views;
2 |
3 | import android.support.v4.view.ViewPager;
4 | import android.view.View;
5 |
6 | public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
7 | private static final float MIN_SCALE = 0.85f;
8 | private static final float MIN_ALPHA = 0.5f;
9 |
10 | public void transformPage(View view, float position) {
11 | int pageWidth = view.getWidth();
12 | int pageHeight = view.getHeight();
13 |
14 | if (position < -1) { // [-Infinity,-1)
15 | // This page is way off-screen to the left.
16 | view.setAlpha(0);
17 |
18 | } else if (position <= 1) { // [-1,1]
19 | // Modify the default slide transition to shrink the page as well
20 | float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
21 | float vertMargin = pageHeight * (1 - scaleFactor) / 2;
22 | float horzMargin = pageWidth * (1 - scaleFactor) / 2;
23 | if (position < 0) {
24 | view.setTranslationX(horzMargin - vertMargin / 2);
25 | } else {
26 | view.setTranslationX(-horzMargin + vertMargin / 2);
27 | }
28 |
29 | // Scale the page down (between MIN_SCALE and 1)
30 | view.setScaleX(scaleFactor);
31 | view.setScaleY(scaleFactor);
32 |
33 | // Fade the page relative to its size.
34 | view.setAlpha(MIN_ALPHA +
35 | (scaleFactor - MIN_SCALE) /
36 | (1 - MIN_SCALE) * (1 - MIN_ALPHA));
37 |
38 | } else { // (1,+Infinity]
39 | // This page is way off-screen to the right.
40 | view.setAlpha(0);
41 | }
42 | }
43 | }
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.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 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
32 |
33 |
38 |
39 |
40 |
41 |
48 |
49 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'realm-android'
3 |
4 |
5 | android {
6 | compileSdkVersion 27
7 | buildToolsVersion '27.0.3'
8 | packagingOptions {
9 | exclude 'META-INF/LICENSE'
10 | exclude 'META-INF/LICENSE-FIREBASE.txt'
11 | exclude 'META-INF/NOTICE'
12 | }
13 | defaultConfig {
14 | applicationId "com.hemant.myfeed"
15 | minSdkVersion 16
16 | targetSdkVersion 27
17 | versionCode 11
18 | versionName "2.0"
19 | }
20 | buildTypes {
21 |
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation 'com.android.support:appcompat-v7:27.1.1'
32 | implementation 'com.android.support:design:27.1.1'
33 | implementation 'com.android.support:cardview-v7:27.1.1'
34 | implementation 'com.android.support:recyclerview-v7:27.1.1'
35 | implementation 'com.einmalfel:earl:1.0.0'
36 | implementation 'com.android.support:support-v4:27.1.1'
37 | implementation 'com.squareup.picasso:picasso:2.5.2'
38 | implementation 'com.jakewharton:butterknife:8.8.1'
39 | implementation 'com.github.zplesac:android_connectionbuddy:v1.0.7@aar'
40 | implementation 'com.prof.rssparser:rssparser:1.1'
41 | implementation 'com.firebase:firebase-client-android:2.5.0'
42 | implementation 'com.android.support:customtabs:27.1.1'
43 | implementation 'com.google.firebase:firebase-ads:15.0.1'
44 | implementation('com.mikepenz:aboutlibraries:5.5.2@aar') {
45 | transitive = true
46 | }
47 | implementation 'com.github.sharish:ShimmerRecyclerView:v1.0'
48 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
49 | testImplementation 'junit:junit:4.12'
50 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
51 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/.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 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/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/res/layout/friends_merge_page.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
27 |
35 |
36 |
37 |
38 |
39 |
45 |
52 |
62 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/AppClass.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 | import android.preference.PreferenceManager;
7 | import android.util.DisplayMetrics;
8 |
9 | import com.firebase.client.Firebase;
10 | import com.zplesac.connectionbuddy.ConnectionBuddy;
11 | import com.zplesac.connectionbuddy.ConnectionBuddyConfiguration;
12 |
13 | import io.realm.Realm;
14 |
15 | /**
16 | * Created by anuraggupta on 31/01/16.
17 | */
18 | public class AppClass extends Application{
19 |
20 | private static AppClass sInstance;
21 | DisplayMetrics metrics;
22 |
23 | @Override
24 | public void onCreate() {
25 | super.onCreate();
26 | sInstance = this;
27 | Firebase.setAndroidContext(this);
28 | ConnectionBuddyConfiguration networkInspectorConfiguration = new ConnectionBuddyConfiguration.Builder(this).build();
29 | ConnectionBuddy.getInstance().init(networkInspectorConfiguration);
30 | Realm.init(this);
31 | }
32 | @Override
33 | public void onTerminate() {
34 | super.onTerminate();
35 | }
36 | public static AppClass getsInstance() {
37 | return sInstance;
38 | }
39 | public static Context getAppContext() {
40 | return sInstance.getApplicationContext();
41 | }
42 | public static void saveToPreferences(Context context, String preferenceName, String preferenceValue) {
43 | SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
44 | SharedPreferences.Editor editor = sharedPreferences.edit();
45 | editor.putString(preferenceName, preferenceValue);
46 | editor.apply();
47 | }
48 |
49 | public static void saveToPreferences(Context context, String preferenceName, boolean preferenceValue) {
50 | SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
51 | SharedPreferences.Editor editor = sharedPreferences.edit();
52 | editor.putBoolean(preferenceName, preferenceValue);
53 | editor.apply();
54 | }
55 |
56 | public static String readFromPreferences(Context context, String preferenceName, String defaultValue) {
57 | SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
58 | return sharedPreferences.getString(preferenceName, defaultValue);
59 | }
60 |
61 | public static boolean readFromPreferences(Context context, String preferenceName, boolean defaultValue) {
62 | SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
63 | return sharedPreferences.getBoolean(preferenceName, defaultValue);
64 | }
65 | public DisplayMetrics getMetrics() {
66 | metrics = new DisplayMetrics();
67 | metrics = getResources().getDisplayMetrics();
68 | return metrics;
69 | }
70 |
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/model/Topic.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.model;
2 |
3 | import com.hemant.myfeed.R;
4 |
5 | import java.util.Map;
6 | import java.util.Objects;
7 |
8 | import io.realm.Realm;
9 | import io.realm.RealmList;
10 | import io.realm.RealmObject;
11 | import io.realm.annotations.PrimaryKey;
12 | import io.realm.annotations.RealmClass;
13 |
14 | /**
15 | * @author Yalantis
16 | */
17 | @RealmClass
18 | public class Topic extends RealmObject {
19 | public int avatar;
20 |
21 | @PrimaryKey private String topic;
22 | public int background;
23 | private String mainLink;
24 | private RealmList interests = new RealmList<>();
25 | public RealmList getLinks() {
26 | return links;
27 | }
28 |
29 | public RealmList getInterests() {
30 | return interests;
31 | }
32 |
33 | public RealmList links = new RealmList<>();
34 |
35 | public Topic(){
36 |
37 | }
38 | public Topic(Realm realm,
39 | String topic,
40 | Map linkTopicPair) {
41 | // Topic topicData = realm.createObject(Topic.class,topic);
42 | switch (topic){
43 | case "Sports" :
44 | this.avatar = R.drawable.sports;
45 | case "Health" :
46 | this.avatar = R.drawable.healthormedical;
47 | case "World" :
48 | this.avatar = R.drawable.world;
49 | case "Politics" :
50 | this.avatar = R.drawable.politics;
51 | case "Science" :
52 | this.avatar = R.drawable.science;
53 | case "Entertainment" :
54 | this.avatar = R.drawable.entertainment;
55 | case "Comics":
56 | this.avatar = R.drawable.comic;
57 | default:
58 | this.avatar = R.mipmap.ic_launcher;
59 | }
60 | this.topic = topic;
61 | this.background = R.color.purple;
62 |
63 | if (linkTopicPair != null){
64 | for (Map.Entry entry : linkTopicPair.entrySet()) {
65 | this.interests.add(StringObject.init(realm, entry.getKey()));
66 | this.links.add(StringObject.init(realm,entry.getValue()));
67 | }
68 |
69 | }
70 | this.mainLink = Objects.requireNonNull(this.links.get(0)).string;
71 | }
72 | public String getTopic() {
73 | return topic;
74 | }
75 |
76 | public void setTopic(String topic) {
77 | this.topic = topic;
78 | }
79 |
80 | public int getAvatar() {
81 | switch (this.topic){
82 | case "Sports" :
83 | return R.drawable.sports;
84 | case "Health" :
85 | return R.drawable.healthormedical;
86 | case "World" :
87 | return R.drawable.world;
88 | case "Politics" :
89 | return R.drawable.politics;
90 | case "Science" :
91 | return R.drawable.science;
92 | case "Entertainment" :
93 | return R.drawable.entertainment;
94 | case "Comics":
95 | return R.drawable.comic;
96 | default:
97 | return R.mipmap.ic_launcher;
98 | }
99 | }
100 |
101 |
102 | public int getBackground() {
103 | return background;
104 | }
105 |
106 | public void setBackground(int background) {
107 | this.background = background;
108 | }
109 |
110 | public String getMainLink() {
111 | return mainLink;
112 | }
113 |
114 |
115 |
116 |
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
23 |
24 |
33 |
34 |
35 |
36 |
44 |
45 |
53 |
54 |
62 |
63 |
71 |
79 |
80 |
88 |
89 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/yalantis/flipviewpager/adapter/BaseFlipAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.yalantis.flipviewpager.adapter;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 |
9 | import com.hemant.myfeed.R;
10 | import com.hemant.myfeed.model.Topic;
11 | import com.hemant.myfeed.yalantis.flipviewpager.utils.FlipSettings;
12 | import com.hemant.myfeed.yalantis.flipviewpager.view.FlipViewPager;
13 |
14 | import java.util.List;
15 |
16 | /**
17 | * @author Yalantis
18 | */
19 | public abstract class BaseFlipAdapter extends BaseAdapter {
20 | private List items;
21 | private FlipSettings settings;
22 | private LayoutInflater inflater;
23 |
24 | public BaseFlipAdapter(Context context, List items, FlipSettings settings) {
25 | this.items = items;
26 | this.settings = settings;
27 | inflater = LayoutInflater.from(context);
28 | }
29 |
30 | @Override
31 | public int getCount() {
32 | // Checking if we need an additional row for single item
33 | return items.size() % 2 != 0 ? ((items.size() / 2) + 1) : (items.size() / 2);
34 | }
35 |
36 | @Override
37 | public T getItem(int position) {
38 | return (T) items.get(position);
39 | }
40 |
41 | @Override
42 | public long getItemId(int position) {
43 | return position;
44 | }
45 |
46 | @Override
47 | public View getView(final int position, View convertView, ViewGroup parent) {
48 | // Trick to divide list into 2 parts
49 | T item1 = getItem(position * 2);
50 | // Used for cases when we have not an even size in incoming list
51 | T item2 = items.size() > (position * 2 + 1) ? getItem(position * 2 + 1) : null;
52 |
53 | final ViewHolder viewHolder;
54 | if (convertView == null)
55 | convertView = inflater.inflate(R.layout.flipper, null);
56 | if (convertView.getTag() != null) {
57 | viewHolder = (ViewHolder) convertView.getTag();
58 | } else {
59 | viewHolder = new ViewHolder();
60 | convertView.setTag(viewHolder);
61 | viewHolder.mFlipViewPager = (FlipViewPager) convertView.findViewById(R.id.flip_view);
62 | }
63 |
64 | // Listener to store flipped page
65 | viewHolder.mFlipViewPager.setOnChangePageListener(new FlipViewPager.OnChangePageListener() {
66 | @Override
67 | public void onFlipped(int page) {
68 | settings.savePageState(position, page);
69 | }
70 | });
71 |
72 | if (viewHolder.mFlipViewPager.getAdapter() == null) {
73 | viewHolder.mFlipViewPager.setAdapter(new MergeAdapter(item1, item2), settings.getDefaultPage(), position, items.size());
74 | } else {
75 | // Recycling internal adapter
76 | // So, it's double recycling - we have only 4-5 mFlipViewPager objects
77 | // and each of them have an adapter
78 | MergeAdapter adapter = (MergeAdapter) viewHolder.mFlipViewPager.getAdapter();
79 | adapter.updateData(item1, item2);
80 | viewHolder.mFlipViewPager.setAdapter(adapter, settings.getPageForPosition(position), position, items.size());
81 | }
82 | return convertView;
83 | }
84 |
85 | public abstract View getPage(int position, View convertView, ViewGroup parent, T item1, T item2);
86 |
87 | public abstract int getPagesCount();
88 |
89 | class ViewHolder {
90 | FlipViewPager mFlipViewPager;
91 | }
92 |
93 | // Adapter merges 2 items together
94 | private class MergeAdapter extends BaseAdapter {
95 | private T item1;
96 | private T item2;
97 |
98 | public MergeAdapter(T item1, T item2) {
99 | this.item1 = item1;
100 | this.item2 = item2;
101 | }
102 |
103 | public void updateData(T item1, T item2) {
104 | this.item1 = item1;
105 | this.item2 = item2;
106 | }
107 |
108 | @Override
109 | public int getCount() {
110 | return item2 == null ? getPagesCount() - 1 : getPagesCount();
111 | }
112 |
113 | @Override
114 | public Object getItem(int position) {
115 | return position; // Stub
116 | }
117 |
118 | @Override
119 | public long getItemId(int position) {
120 | return position; // Stub
121 | }
122 |
123 | @Override
124 | public View getView(int position, View convertView, ViewGroup parent) {
125 | return getPage(position, convertView, parent, item1, item2);
126 | }
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/Util/RVAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.Util;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.CardView;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.webkit.WebView;
10 | import android.webkit.WebViewClient;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 |
14 | import com.einmalfel.earl.Item;
15 | import com.hemant.myfeed.R;
16 | import com.squareup.picasso.Picasso;
17 |
18 | import java.util.ArrayList;
19 |
20 | import butterknife.BindView;
21 | import butterknife.ButterKnife;
22 |
23 |
24 | public class RVAdapter extends RecyclerView.Adapter {
25 | Context mContext;
26 |
27 | CustomItemClickListener listener;
28 | public static class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
29 | @BindView(R.id.cv)
30 | CardView cv;
31 | @BindView(R.id.person_name)
32 | TextView titleLabel;
33 | @BindView(R.id.person_age)
34 | WebView webview;
35 | @BindView(R.id.person_photo)
36 | ImageView Photo;
37 |
38 |
39 | PersonViewHolder(View itemView) {
40 | super(itemView);
41 | ButterKnife.bind(this,itemView);
42 | cv.setCardElevation(8);
43 | }
44 |
45 | @Override
46 | public void onClick(View v) {
47 |
48 | }
49 | }
50 |
51 | ArrayList- RssItems;
52 |
53 | public RVAdapter(Context mContext, ArrayList
- RssItems, CustomItemClickListener listener) {
54 |
55 | try {
56 | this.RssItems = RssItems;
57 | this.mContext = mContext;
58 | this.listener = listener;
59 | } catch (Exception e) {
60 | e.printStackTrace();
61 | }
62 | }
63 |
64 | @Override
65 | public void onAttachedToRecyclerView(RecyclerView recyclerView) {
66 | super.onAttachedToRecyclerView(recyclerView);
67 |
68 | }
69 |
70 | @Override
71 | public PersonViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
72 | View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);
73 | return new PersonViewHolder(v);
74 | }
75 |
76 | @Override
77 | public void onBindViewHolder(final PersonViewHolder personViewHolder, final int i) {
78 | personViewHolder.titleLabel.setText(RssItems.get(i).getTitle());
79 | personViewHolder.cv.setOnClickListener(new View.OnClickListener() {
80 | @Override
81 | public void onClick(View v) {
82 | listener.onItemClick(personViewHolder.cv,i);
83 | }
84 | });
85 | personViewHolder.webview.setOnClickListener(new View.OnClickListener() {
86 | @Override
87 | public void onClick(View v) {
88 | listener.onItemClick(personViewHolder.cv,i);
89 | }
90 | });
91 |
92 | personViewHolder.webview.setWebViewClient(new WebViewClient()
93 | {
94 | @Override
95 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
96 |
97 | listener.onItemClick(personViewHolder.cv,i);
98 |
99 | return true;
100 | }
101 | });
102 |
103 |
104 | personViewHolder.webview.loadDataWithBaseURL(null, "" + RssItems.get(i).getDescription() + "", "text/html", "utf-8", null);
105 |
106 | if(RssItems.get(i).getImageLink() != null) {
107 | Picasso.with(mContext).load((RssItems.get(i).getImageLink())).into(personViewHolder.Photo);
108 | }
109 | // else {
110 | // String html = RssItems.get(i).getDescription();
111 | // String imgRegex = "<[iI][mM][gG][^>]+[sS][rR][cC]\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
112 | //
113 | // Pattern p = Pattern.compile(imgRegex);
114 | // Matcher m = p.matcher(html);
115 | //
116 | // if (m.find()) {
117 | // try {
118 | // Picasso.with(mContext).load(String.valueOf(new URL(m.group(1)))).resize(80,80).into(personViewHolder.Photo);
119 | // } catch (MalformedURLException e) {
120 | // e.printStackTrace();
121 | // }
122 | // }
123 | // else {
124 | //
125 | // Uri data = Uri.parse(RssItems.get(i).getLink());
126 | // try {
127 | // Picasso.with(mContext).load(new String(String.valueOf(new URL(data.getScheme(), data.getHost(), "/favicon.ico")))).into(personViewHolder.Photo);
128 | // } catch (MalformedURLException e) {
129 | // e.printStackTrace();
130 | // }
131 | //
132 | // }
133 | // }
134 |
135 | // setAnimation(personViewHolder.cv, i);
136 | }
137 | // private void setAnimation(View viewToAnimate, int position)
138 | // {
139 | // // If the bound view wasn't previously displayed on screen, it's animated
140 | // if (position > lastPosition)
141 | // {
142 | // Animation animation = AnimationUtils.loadAnimation(mContext, android.R.anim.slide_in_left);
143 | // viewToAnimate.startAnimation(animation);
144 | // lastPosition = position;
145 | // }
146 | // }
147 | @Override
148 | public int getItemCount() {
149 | return RssItems.size();
150 | }
151 |
152 | }
--------------------------------------------------------------------------------
/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/hemant/myfeed/fragments/BlankFragment.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.fragments;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.os.AsyncTask;
6 | import android.os.Bundle;
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 | import android.support.customtabs.CustomTabsIntent;
10 | import android.support.v4.app.Fragment;
11 | import android.support.v4.content.ContextCompat;
12 | import android.support.v7.widget.LinearLayoutManager;
13 | import android.util.Log;
14 | import android.view.LayoutInflater;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.widget.Toast;
18 |
19 | import com.cooltechworks.views.shimmer.ShimmerRecyclerView;
20 | import com.einmalfel.earl.EarlParser;
21 | import com.einmalfel.earl.Enclosure;
22 | import com.einmalfel.earl.Feed;
23 | import com.einmalfel.earl.Item;
24 | import com.google.android.gms.ads.AdRequest;
25 | import com.google.android.gms.ads.AdView;
26 | import com.hemant.myfeed.R;
27 | import com.hemant.myfeed.Util.CustomItemClickListener;
28 | import com.hemant.myfeed.Util.RVAdapter;
29 | import com.prof.rssparser.Article;
30 | import com.prof.rssparser.Parser;
31 |
32 | import java.io.InputStream;
33 | import java.net.URL;
34 | import java.util.ArrayList;
35 | import java.util.Date;
36 | import java.util.List;
37 |
38 | import butterknife.BindView;
39 | import butterknife.ButterKnife;
40 |
41 |
42 | /**
43 | * A simple {@link Fragment} subclass.
44 | * Activities that contain this fragment must implement the
45 | * {@link BlankFragment.OnFragmentInteractionListener} interface
46 | * to handle interaction events.
47 | * Use the {@link BlankFragment#newInstance} factory method to
48 | * create an instance of this fragment.
49 | */
50 | public class BlankFragment extends Fragment {
51 | // TODO: Rename parameter arguments, choose names that match
52 | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
53 | private static final String ARG_PARAM1 = "param1";
54 |
55 | @BindView(R.id.rv)
56 | ShimmerRecyclerView rv;
57 | @BindView(R.id.adView)
58 | AdView adView;
59 | private ArrayList
- RssItems;
60 | // TODO: Rename and change types of parameters
61 | private String mParam1;
62 |
63 |
64 | private OnFragmentInteractionListener mListener;
65 |
66 | public BlankFragment() {
67 | // Required empty public constructor
68 | }
69 |
70 | /**
71 | * Use this factory method to create a new instance of
72 | * this fragment using the provided parameters.
73 | *
74 | * @param param1 Parameter 1.
75 | * @return A new instance of fragment BlankFragment.
76 | */
77 | // TODO: Rename and change types and number of parameters
78 | public static BlankFragment newInstance(String param1) {
79 | BlankFragment fragment = new BlankFragment();
80 | Bundle args = new Bundle();
81 | args.putString(ARG_PARAM1, param1);
82 | fragment.setArguments(args);
83 | return fragment;
84 | }
85 |
86 | @Override
87 | public void onCreate(Bundle savedInstanceState) {
88 | super.onCreate(savedInstanceState);
89 | if (getArguments() != null) {
90 | mParam1 = getArguments().getString(ARG_PARAM1);
91 | }
92 | }
93 |
94 | @Override
95 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
96 | Bundle savedInstanceState) {
97 | // Inflate the layout for this fragment
98 | View rootView = inflater.inflate(R.layout.fragment_blank, container, false);
99 | ButterKnife.bind(this, rootView);
100 | LinearLayoutManager llm = new LinearLayoutManager(getActivity());
101 | rv.setLayoutManager(llm);
102 | rv.setHasFixedSize(false);
103 | rv.showShimmerAdapter();
104 | RssItems = new ArrayList<>();
105 | AdRequest adRequest = new AdRequest.Builder().build();
106 | adView.loadAd(adRequest);
107 | new GetRssFeed().execute(mParam1);
108 | // new GetRssFeed().execute("http://feeds.reuters.com/reuters/INoddlyEnoughNews");
109 | return rootView;
110 | }
111 | private void secondaryParser(){
112 | Parser parser = new Parser();
113 | parser.execute(mParam1);
114 | parser.onFinish(new Parser.OnTaskCompleted() {
115 |
116 | @Override
117 | public void onTaskCompleted(ArrayList list) {
118 | //what to do when the parsing is done
119 | //the Array List contains all article's data. For example you can use it for your adapter.
120 | for (final Article article : list){
121 | Item item = new Item() {
122 | @Nullable
123 | @Override
124 | public String getLink() {
125 | return article.getLink();
126 | }
127 |
128 | @Nullable
129 | @Override
130 | public Date getPublicationDate() {
131 | return article.getPubDate();
132 | }
133 |
134 | @Nullable
135 | @Override
136 | public String getTitle() {
137 | return article.getTitle();
138 | }
139 |
140 | @Nullable
141 | @Override
142 | public String getDescription() {
143 | return article.getDescription();
144 | }
145 |
146 | @Nullable
147 | @Override
148 | public String getImageLink() {
149 | return article.getImage();
150 | }
151 |
152 | @Nullable
153 | @Override
154 | public String getAuthor() {
155 | return article.getAuthor();
156 | }
157 |
158 | @NonNull
159 | @Override
160 | public List extends Enclosure> getEnclosures() {
161 | return null;
162 | }
163 | };
164 | RssItems.add(item);
165 | }
166 | initializeAdapter();
167 | }
168 |
169 | @Override
170 | public void onError() {
171 | //what to do in case of error
172 | Toast.makeText(getContext(),"Cannot get NEWS Feed. Try any other channel.",Toast.LENGTH_LONG).show();
173 | }
174 | });
175 | }
176 | private void initializeAdapter() {
177 |
178 | RVAdapter adapter = new RVAdapter(getActivity(), RssItems, new CustomItemClickListener() {
179 | @Override
180 | public void onItemClick(View v, int position) {
181 | String url = RssItems.get(position).getLink();
182 | CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
183 | builder.setToolbarColor(ContextCompat.getColor(getActivity(), R.color.colorAccent));
184 | CustomTabsIntent customTabsIntent = builder.build();
185 | customTabsIntent.launchUrl(getActivity(), Uri.parse(url));
186 | }
187 | });
188 | adapter.notifyDataSetChanged();
189 | if (rv != null) {
190 | rv.hideShimmerAdapter();
191 | rv.setAdapter(adapter);
192 | }
193 |
194 | }
195 |
196 | // TODO: Rename method, update argument and hook method into UI event
197 | public void onButtonPressed(Uri uri) {
198 | if (mListener != null) {
199 | mListener.onFragmentInteraction(uri);
200 | }
201 | }
202 |
203 | @Override
204 | public void onAttach(Context context) {
205 | super.onAttach(context);
206 | if (context instanceof OnFragmentInteractionListener) {
207 | mListener = (OnFragmentInteractionListener) context;
208 | } else {
209 | throw new RuntimeException(context.toString()
210 | + " must implement OnFragmentInteractionListener");
211 | }
212 | }
213 |
214 | @Override
215 | public void onDetach() {
216 | super.onDetach();
217 | mListener = null;
218 | }
219 |
220 | /**
221 | * This interface must be implemented by activities that contain this
222 | * fragment to allow an interaction in this fragment to be communicated
223 | * to the activity and potentially other fragments contained in that
224 | * activity.
225 | *
226 | * See the Android Training lesson Communicating with Other Fragments for more information.
229 | */
230 | public interface OnFragmentInteractionListener {
231 | // TODO: Update argument type and name
232 | void onFragmentInteraction(Uri uri);
233 | }
234 | private class GetRssFeed extends AsyncTask {
235 | @Override
236 | protected Void doInBackground(String... params) {
237 | try {
238 | InputStream inputStream = new URL(params[0]).openConnection().getInputStream();
239 | Feed feed = EarlParser.parseOrThrow(inputStream, 0);
240 |
241 | RssItems.addAll(feed.getItems());
242 |
243 | } catch (Exception e) {
244 | Log.v("Error Parsing Data", e + "");
245 | }
246 | return null;
247 | }
248 |
249 | @Override
250 | protected void onPostExecute(Void aVoid) {
251 | super.onPostExecute(aVoid);
252 | if (RssItems.isEmpty()){
253 | Toast.makeText(getContext(), "Try other approach.", Toast.LENGTH_SHORT).show();
254 | secondaryParser();
255 | }
256 | else {
257 | initializeAdapter();
258 | }
259 | }
260 | }
261 |
262 | @Override
263 | public void onDestroy() {
264 | super.onDestroy();
265 | }
266 |
267 | }
268 |
--------------------------------------------------------------------------------
/app/src/main/java/com/hemant/myfeed/fragments/MainFragment.java:
--------------------------------------------------------------------------------
1 | package com.hemant.myfeed.fragments;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import android.support.v4.app.Fragment;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.AdapterView;
11 | import android.widget.Button;
12 | import android.widget.ImageView;
13 | import android.widget.ListView;
14 | import android.widget.TextView;
15 |
16 | import com.hemant.myfeed.Activities.MainActivity;
17 | import com.hemant.myfeed.R;
18 | import com.hemant.myfeed.model.StringObject;
19 | import com.hemant.myfeed.model.Topic;
20 | import com.hemant.myfeed.yalantis.flipviewpager.adapter.BaseFlipAdapter;
21 | import com.hemant.myfeed.yalantis.flipviewpager.utils.FlipSettings;
22 | import com.squareup.picasso.Picasso;
23 |
24 | import java.util.ArrayList;
25 | import java.util.Iterator;
26 | import java.util.List;
27 |
28 | import butterknife.BindView;
29 | import butterknife.BindViews;
30 | import butterknife.ButterKnife;
31 | import io.realm.Realm;
32 | import io.realm.RealmConfiguration;
33 | import io.realm.RealmResults;
34 |
35 | /**
36 | * A simple {@link Fragment} subclass.
37 | * Activities that contain this fragment must implement the
38 | * {@link MainFragment.OnFragmentInteractionListener} interface
39 | * to handle interaction events.
40 | * Use the {@link MainFragment#newInstance} factory method to
41 | * create an instance of this fragment.
42 | */
43 | public class MainFragment extends Fragment{
44 | // TODO: Rename parameter arguments, choose names that match
45 | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
46 | private static final String ARG_PARAM1 = "param1";
47 | private static final String ARG_PARAM2 = "param2";
48 | private Realm realm;
49 | MainActivity myParentActivity;
50 | // TODO: Rename and change types of parameters
51 | private String mParam1;
52 | @BindView(R.id.friends)
53 | public ListView friends;
54 |
55 | private String mParam2;
56 |
57 | private OnFragmentInteractionListener mListener;
58 |
59 | public MainFragment() {
60 | // Required empty public constructor
61 | }
62 |
63 | /**
64 | * Use this factory method to create a new instance of
65 | * this fragment using the provided parameters.
66 | *
67 | * @param param1 Parameter 1.
68 | * @param param2 Parameter 2.
69 | * @return A new instance of fragment MainFragment.
70 | */
71 |
72 | // TODO: Rename and change types and number of parameters
73 | public static MainFragment newInstance(String param1, String param2) {
74 | MainFragment fragment = new MainFragment();
75 | Bundle args = new Bundle();
76 | args.putString(ARG_PARAM1, param1);
77 | args.putString(ARG_PARAM2, param2);
78 | fragment.setArguments(args);
79 | return fragment;
80 | }
81 |
82 | @Override
83 | public void onCreate(Bundle savedInstanceState) {
84 | super.onCreate(savedInstanceState);
85 | if (getArguments() != null) {
86 | mParam1 = getArguments().getString(ARG_PARAM1);
87 | mParam2 = getArguments().getString(ARG_PARAM2);
88 | }
89 | myParentActivity = (MainActivity) getActivity();
90 | }
91 |
92 | @Override
93 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
94 | Bundle savedInstanceState) {
95 | // Inflate the layout for this fragment
96 | Realm.init(getContext());
97 | RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().name(Realm.DEFAULT_REALM_NAME)
98 | .schemaVersion(0)
99 | .deleteRealmIfMigrationNeeded()
100 | .build();
101 | realm = Realm.getInstance(realmConfiguration);
102 | View rootView = inflater.inflate(R.layout.fragment_main, container, false);
103 | ButterKnife.bind(this,rootView);
104 | friends.setOnItemClickListener(new AdapterView.OnItemClickListener() {
105 | @Override
106 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
107 |
108 | myParentActivity.setUrl(realm.where(Topic.class).findAll().get(position).getMainLink());
109 |
110 | }
111 | });
112 |
113 | reloadList();
114 | return rootView;
115 | }
116 | public void reloadList(){
117 | FlipSettings settings = new FlipSettings.Builder().defaultPage(1).build();
118 | RealmResults topics = realm.where(Topic.class).notEqualTo("avatar",0).findAll();
119 | friends.setAdapter(new FriendsAdapter(getActivity(),topics , settings));
120 | }
121 | // TODO: Rename method, update argument and hook method into UI event
122 | public void onButtonPressed(Uri uri) {
123 | if (mListener != null) {
124 | mListener.onFragmentInteraction(uri);
125 | }
126 | }
127 |
128 | @Override
129 | public void onAttach(Context context) {
130 | super.onAttach(context);
131 | if (context instanceof OnFragmentInteractionListener) {
132 | mListener = (OnFragmentInteractionListener) context;
133 | } else {
134 | throw new RuntimeException(context.toString()
135 | + " must implement OnFragmentInteractionListener");
136 | }
137 | }
138 | @Override
139 | public void onDetach() {
140 | super.onDetach();
141 | mListener = null;
142 | }
143 | public interface OnFragmentInteractionListener {
144 | // TODO: Update argument type and name
145 | void onFragmentInteraction(Uri uri);
146 | }
147 | class FriendsAdapter extends BaseFlipAdapter {
148 |
149 | int PAGES = 3;
150 | private int[] IDS_INTEREST = {R.id.interest_1, R.id.interest_2, R.id.interest_3,R.id.interest_4,R.id.interest_5,R.id.interest_6};
151 | @BindViews({R.id.interest_1, R.id.interest_2, R.id.interest_3,R.id.interest_4,R.id.interest_5,R.id.interest_6})
152 | List