├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── coffee01.jpg
│ │ │ │ ├── coffee02.jpg
│ │ │ │ ├── coffee03.jpg
│ │ │ │ ├── coffee04.jpg
│ │ │ │ ├── coffee05.jpg
│ │ │ │ ├── coffee06.jpg
│ │ │ │ ├── coffee07.jpg
│ │ │ │ ├── coffee08.jpg
│ │ │ │ ├── coffee09.jpg
│ │ │ │ └── coffee10.jpg
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── coffee01.jpg
│ │ │ │ ├── coffee02.jpg
│ │ │ │ ├── coffee03.jpg
│ │ │ │ ├── coffee04.jpg
│ │ │ │ ├── coffee05.jpg
│ │ │ │ ├── coffee06.jpg
│ │ │ │ ├── coffee07.jpg
│ │ │ │ ├── coffee08.jpg
│ │ │ │ ├── coffee09.jpg
│ │ │ │ └── coffee10.jpg
│ │ │ ├── drawable
│ │ │ │ ├── bottom_scroll.png
│ │ │ │ ├── ic_home_black_24dp.xml
│ │ │ │ ├── ic_dashboard_black_24dp.xml
│ │ │ │ ├── ic_favorite_red_24dp.xml
│ │ │ │ ├── ic_favorite_shadow_24dp.xml
│ │ │ │ ├── ic_notifications_black_24dp.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── coffee01.jpg
│ │ │ │ ├── coffee02.jpg
│ │ │ │ ├── coffee03.jpg
│ │ │ │ ├── coffee04.jpg
│ │ │ │ ├── coffee05.jpg
│ │ │ │ ├── coffee06.jpg
│ │ │ │ ├── coffee07.jpg
│ │ │ │ ├── coffee08.jpg
│ │ │ │ ├── coffee09.jpg
│ │ │ │ └── coffee10.jpg
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── coffee01.jpg
│ │ │ │ ├── coffee02.jpg
│ │ │ │ ├── coffee03.jpg
│ │ │ │ ├── coffee04.jpg
│ │ │ │ ├── coffee05.jpg
│ │ │ │ ├── coffee06.jpg
│ │ │ │ ├── coffee07.jpg
│ │ │ │ ├── coffee08.jpg
│ │ │ │ ├── coffee09.jpg
│ │ │ │ └── coffee10.jpg
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── coffee01.jpg
│ │ │ │ ├── coffee02.jpg
│ │ │ │ ├── coffee03.jpg
│ │ │ │ ├── coffee04.jpg
│ │ │ │ ├── coffee05.jpg
│ │ │ │ ├── coffee06.jpg
│ │ │ │ ├── coffee07.jpg
│ │ │ │ ├── coffee08.jpg
│ │ │ │ ├── coffee09.jpg
│ │ │ │ └── coffee10.jpg
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ └── bottom_nav_menu.xml
│ │ │ ├── layout
│ │ │ │ ├── fragment_notifications.xml
│ │ │ │ ├── fragment_dashboard.xml
│ │ │ │ ├── fragment_home.xml
│ │ │ │ ├── fav_item.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── item.xml
│ │ │ ├── navigation
│ │ │ │ └── mobile_navigation.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── ru
│ │ │ │ └── embersoft
│ │ │ │ └── favoritelist
│ │ │ │ ├── Helpers
│ │ │ │ ├── FirebaseApp.java
│ │ │ │ ├── FavItem.java
│ │ │ │ ├── CoffeeItem.java
│ │ │ │ └── FavDB.java
│ │ │ │ ├── Fragments
│ │ │ │ ├── NotificationsFragment.java
│ │ │ │ ├── HomeFragment.java
│ │ │ │ └── DashboardFragment.java
│ │ │ │ ├── Activities
│ │ │ │ └── MainActivity.java
│ │ │ │ └── Adapters
│ │ │ │ ├── FavAdapter.java
│ │ │ │ └── CoffeeAdapter.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── ru
│ │ │ └── embersoft
│ │ │ └── favoritelist
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── ru
│ │ └── embersoft
│ │ └── favoritelist
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .idea
├── runConfigurations.xml
├── misc.xml
├── gradle.xml
└── codeStyles
│ └── Project.xml
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='FavoriteList'
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee01.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee02.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee03.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee03.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee04.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee04.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee05.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee05.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee06.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee06.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee07.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee07.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee08.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee08.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee09.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee09.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/coffee10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-hdpi/coffee10.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee01.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee02.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee03.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee03.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee04.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee04.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee05.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee05.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee06.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee06.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee07.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee07.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee08.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee08.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee09.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee09.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/coffee10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-mdpi/coffee10.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bottom_scroll.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable/bottom_scroll.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee01.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee02.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee03.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee03.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee04.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee04.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee05.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee05.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee06.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee06.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee07.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee07.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee08.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee08.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee09.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee09.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/coffee10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xhdpi/coffee10.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee01.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee02.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee03.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee03.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee04.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee04.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee05.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee05.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee06.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee06.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee07.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee07.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee08.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee08.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee09.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee09.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/coffee10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxhdpi/coffee10.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee01.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee02.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee02.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee03.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee03.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee04.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee04.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee05.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee05.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee06.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee06.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee07.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee07.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee08.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee08.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee09.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee09.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/coffee10.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/drawable-xxxhdpi/coffee10.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gifffert/FavoriteList/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FavoriteList
3 | Home
4 | Dashboard
5 | Notifications
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Feb 14 15:40:22 YAKT 2020
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-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_home_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_dashboard_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Helpers/FirebaseApp.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Helpers;
2 |
3 | import com.google.firebase.database.FirebaseDatabase;
4 |
5 | public class FirebaseApp extends android.app.Application {
6 |
7 | @Override
8 | public void onCreate() {
9 | super.onCreate();
10 |
11 | //enable offline data on firebase database
12 | FirebaseDatabase.getInstance().setPersistenceEnabled(true);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_favorite_red_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_favorite_shadow_24dp.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/test/java/ru/embersoft/favoritelist/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist;
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() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_notifications_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/bottom_nav_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Fragments/NotificationsFragment.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Fragments;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.fragment.app.Fragment;
11 |
12 | import ru.embersoft.favoritelist.R;
13 |
14 | public class NotificationsFragment extends Fragment {
15 |
16 |
17 | public View onCreateView(@NonNull LayoutInflater inflater,
18 | ViewGroup container, Bundle savedInstanceState) {
19 | View root = inflater.inflate(R.layout.fragment_notifications, container, false);
20 | final TextView textView = root.findViewById(R.id.text_notifications);
21 | return root;
22 | }
23 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_notifications.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
19 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/ru/embersoft/favoritelist/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 |
25 | assertEquals("ru.embersoft.favoritelist", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Helpers/FavItem.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Helpers;
2 |
3 | public class FavItem {
4 |
5 | private String item_title;
6 | private String key_id;
7 | private int item_image;
8 |
9 | public FavItem() {
10 | }
11 |
12 | public FavItem(String item_title, String key_id, int item_image) {
13 | this.item_title = item_title;
14 | this.key_id = key_id;
15 | this.item_image = item_image;
16 | }
17 |
18 | public String getItem_title() {
19 | return item_title;
20 | }
21 |
22 | public void setItem_title(String item_title) {
23 | this.item_title = item_title;
24 | }
25 |
26 | public String getKey_id() {
27 | return key_id;
28 | }
29 |
30 | public void setKey_id(String key_id) {
31 | this.key_id = key_id;
32 | }
33 |
34 | public int getItem_image() {
35 | return item_image;
36 | }
37 |
38 | public void setItem_image(int item_image) {
39 | this.item_image = item_image;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/mobile_navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_dashboard.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
18 |
19 |
22 |
23 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
19 |
20 |
23 |
24 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Helpers/CoffeeItem.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Helpers;
2 |
3 | public class CoffeeItem {
4 |
5 | private int imageResourse;
6 | private String title;
7 | private String key_id;
8 | private String favStatus;
9 |
10 | public CoffeeItem() {
11 | }
12 |
13 | public CoffeeItem(int imageResourse, String title, String key_id, String favStatus) {
14 | this.imageResourse = imageResourse;
15 | this.title = title;
16 | this.key_id = key_id;
17 | this.favStatus = favStatus;
18 | }
19 |
20 | public int getImageResourse() {
21 | return imageResourse;
22 | }
23 |
24 | public void setImageResourse(int imageResourse) {
25 | this.imageResourse = imageResourse;
26 | }
27 |
28 | public String getTitle() {
29 | return title;
30 | }
31 |
32 | public void setTitle(String title) {
33 | this.title = title;
34 | }
35 |
36 | public String getKey_id() {
37 | return key_id;
38 | }
39 |
40 | public void setKey_id(String key_id) {
41 | this.key_id = key_id;
42 | }
43 |
44 | public String getFavStatus() {
45 | return favStatus;
46 | }
47 |
48 | public void setFavStatus(String favStatus) {
49 | this.favStatus = favStatus;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fav_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
25 |
26 |
33 |
34 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Activities/MainActivity.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Activities;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.google.android.material.bottomnavigation.BottomNavigationView;
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 | import androidx.navigation.NavController;
9 | import androidx.navigation.Navigation;
10 | import androidx.navigation.ui.AppBarConfiguration;
11 | import androidx.navigation.ui.NavigationUI;
12 |
13 | import ru.embersoft.favoritelist.R;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | BottomNavigationView navView = findViewById(R.id.nav_view);
22 | // Passing each menu ID as a set of Ids because each
23 | // menu should be considered as top level destinations.
24 | AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
25 | R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications)
26 | .build();
27 | NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
28 | NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
29 | NavigationUI.setupWithNavController(navView, navController);
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
19 |
20 |
31 |
32 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.google.gms.google-services'
3 |
4 | android {
5 | compileSdkVersion 29
6 | buildToolsVersion "29.0.2"
7 | defaultConfig {
8 | applicationId "ru.embersoft.favoritelist"
9 | minSdkVersion 21
10 | targetSdkVersion 29
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(dir: 'libs', include: ['*.jar'])
25 | implementation 'androidx.appcompat:appcompat:1.1.0'
26 | implementation 'com.google.android.material:material:1.1.0'
27 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
28 | implementation 'androidx.navigation:navigation-fragment:2.2.1'
29 | implementation 'androidx.navigation:navigation-ui:2.2.1'
30 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
31 | implementation 'com.google.firebase:firebase-database:16.0.4'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'androidx.test.ext:junit:1.1.1'
34 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
35 | // cardview and recyclerview
36 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
37 | implementation 'androidx.cardview:cardview:1.0.0'
38 | // bounce scroll like iOS
39 | implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0'
40 | implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0'
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Fragments/HomeFragment.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Fragments;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import androidx.annotation.NonNull;
9 | import androidx.fragment.app.Fragment;
10 | import androidx.recyclerview.widget.LinearLayoutManager;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | import java.util.ArrayList;
14 |
15 | import ru.embersoft.favoritelist.Adapters.CoffeeAdapter;
16 | import ru.embersoft.favoritelist.Helpers.CoffeeItem;
17 | import ru.embersoft.favoritelist.R;
18 |
19 | public class HomeFragment extends Fragment {
20 |
21 | private ArrayList coffeeItems = new ArrayList<>();
22 |
23 | public View onCreateView(@NonNull LayoutInflater inflater,
24 | ViewGroup container, Bundle savedInstanceState) {
25 | View root = inflater.inflate(R.layout.fragment_home, container, false);
26 |
27 | RecyclerView recyclerView = root.findViewById(R.id.recyclerView);
28 | recyclerView.setHasFixedSize(true);
29 | recyclerView.setAdapter(new CoffeeAdapter(coffeeItems, getActivity()));
30 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
31 |
32 | coffeeItems.add(new CoffeeItem(R.drawable.coffee01, "Latte","0","0"));
33 | coffeeItems.add(new CoffeeItem(R.drawable.coffee02, "Kapucino","1","0"));
34 | coffeeItems.add(new CoffeeItem(R.drawable.coffee03, "Raf","2","0"));
35 | coffeeItems.add(new CoffeeItem(R.drawable.coffee04, "Milk Shake","3","0"));
36 | coffeeItems.add(new CoffeeItem(R.drawable.coffee05, "Magic Coffee","4","0"));
37 | coffeeItems.add(new CoffeeItem(R.drawable.coffee06, "Swedish Coffee","5","0"));
38 | coffeeItems.add(new CoffeeItem(R.drawable.coffee07, "Mint Coffee","6","0"));
39 | coffeeItems.add(new CoffeeItem(R.drawable.coffee08, "Espresso","7","0"));
40 | coffeeItems.add(new CoffeeItem(R.drawable.coffee09, "Americano","8","0"));
41 |
42 | return root;
43 | }
44 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
31 |
32 |
39 |
40 |
45 |
46 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Helpers/FavDB.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Helpers;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.database.sqlite.SQLiteOpenHelper;
8 | import android.util.Log;
9 |
10 | public class FavDB extends SQLiteOpenHelper {
11 |
12 | private static int DB_VERSION = 1;
13 | private static String DATABASE_NAME = "CoffeeDB";
14 | private static String TABLE_NAME = "favoriteTable";
15 | public static String KEY_ID = "id";
16 | public static String ITEM_TITLE = "itemTitle";
17 | public static String ITEM_IMAGE = "itemImage";
18 | public static String FAVORITE_STATUS = "fStatus";
19 | // dont forget write this spaces
20 | private static String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "("
21 | + KEY_ID + " TEXT," + ITEM_TITLE+ " TEXT,"
22 | + ITEM_IMAGE + " TEXT," + FAVORITE_STATUS+" TEXT)";
23 |
24 | public FavDB(Context context) { super(context,DATABASE_NAME,null,DB_VERSION);}
25 |
26 | @Override
27 | public void onCreate(SQLiteDatabase sqLiteDatabase) {
28 | sqLiteDatabase.execSQL(CREATE_TABLE);
29 | }
30 |
31 | @Override
32 | public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
33 |
34 | }
35 |
36 | // create empty table
37 | public void insertEmpty() {
38 | SQLiteDatabase db = this.getWritableDatabase();
39 | ContentValues cv = new ContentValues();
40 | // enter your value
41 | for (int x = 1; x < 11; x++) {
42 | cv.put(KEY_ID, x);
43 | cv.put(FAVORITE_STATUS, "0");
44 |
45 | db.insert(TABLE_NAME,null, cv);
46 | }
47 | }
48 |
49 | // insert data into database
50 | public void insertIntoTheDatabase(String item_title, int item_image, String id, String fav_status) {
51 | SQLiteDatabase db;
52 | db = this.getWritableDatabase();
53 | ContentValues cv = new ContentValues();
54 | cv.put(ITEM_TITLE, item_title);
55 | cv.put(ITEM_IMAGE, item_image);
56 | cv.put(KEY_ID, id);
57 | cv.put(FAVORITE_STATUS, fav_status);
58 | db.insert(TABLE_NAME,null, cv);
59 | Log.d("FavDB Status", item_title + ", favstatus - "+fav_status+" - . " + cv);
60 | }
61 |
62 | // read all data
63 | public Cursor read_all_data(String id) {
64 | SQLiteDatabase db = this.getReadableDatabase();
65 | String sql = "select * from " + TABLE_NAME + " where " + KEY_ID+"="+id+"";
66 | return db.rawQuery(sql,null,null);
67 | }
68 |
69 | // remove line from database
70 | public void remove_fav(String id) {
71 | SQLiteDatabase db = this.getWritableDatabase();
72 | String sql = "UPDATE " + TABLE_NAME + " SET "+ FAVORITE_STATUS+" ='0' WHERE "+KEY_ID+"="+id+"";
73 | db.execSQL(sql);
74 | Log.d("remove", id.toString());
75 |
76 | }
77 |
78 | // select all favorite list
79 |
80 | public Cursor select_all_favorite_list() {
81 | SQLiteDatabase db = this.getReadableDatabase();
82 | String sql = "SELECT * FROM "+TABLE_NAME+" WHERE "+FAVORITE_STATUS+" ='1'";
83 | return db.rawQuery(sql,null,null);
84 | }
85 |
86 |
87 |
88 |
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | xmlns:android
11 |
12 | ^$
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | xmlns:.*
22 |
23 | ^$
24 |
25 |
26 | BY_NAME
27 |
28 |
29 |
30 |
31 |
32 |
33 | .*:id
34 |
35 | http://schemas.android.com/apk/res/android
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | .*:name
45 |
46 | http://schemas.android.com/apk/res/android
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | name
56 |
57 | ^$
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | style
67 |
68 | ^$
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 | .*
78 |
79 | ^$
80 |
81 |
82 | BY_NAME
83 |
84 |
85 |
86 |
87 |
88 |
89 | .*
90 |
91 | http://schemas.android.com/apk/res/android
92 |
93 |
94 | ANDROID_ATTRIBUTE_ORDER
95 |
96 |
97 |
98 |
99 |
100 |
101 | .*
102 |
103 | .*
104 |
105 |
106 | BY_NAME
107 |
108 |
109 |
110 |
111 |
112 |
113 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Fragments/DashboardFragment.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Fragments;
2 |
3 | import android.database.Cursor;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.os.Bundle;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.fragment.app.Fragment;
12 | import androidx.recyclerview.widget.ItemTouchHelper;
13 | import androidx.recyclerview.widget.LinearLayoutManager;
14 | import androidx.recyclerview.widget.RecyclerView;
15 |
16 | import java.util.ArrayList;
17 | import java.util.List;
18 |
19 | import ru.embersoft.favoritelist.Adapters.FavAdapter;
20 | import ru.embersoft.favoritelist.Helpers.FavDB;
21 | import ru.embersoft.favoritelist.Helpers.FavItem;
22 | import ru.embersoft.favoritelist.R;
23 |
24 | public class DashboardFragment extends Fragment {
25 |
26 | private RecyclerView recyclerView;
27 | private FavDB favDB;
28 | private List favItemList = new ArrayList<>();
29 | private FavAdapter favAdapter;
30 |
31 | public View onCreateView(@NonNull LayoutInflater inflater,
32 | ViewGroup container, Bundle savedInstanceState) {
33 | View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
34 |
35 | favDB = new FavDB(getActivity());
36 | recyclerView = root.findViewById(R.id.recyclerView);
37 | recyclerView.setHasFixedSize(true);
38 | recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
39 |
40 | // add item touch helper
41 | ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
42 | itemTouchHelper.attachToRecyclerView(recyclerView); // set swipe to recyclerview
43 |
44 | loadData();
45 |
46 | return root;
47 | }
48 |
49 | private void loadData() {
50 | if (favItemList != null) {
51 | favItemList.clear();
52 | }
53 | SQLiteDatabase db = favDB.getReadableDatabase();
54 | Cursor cursor = favDB.select_all_favorite_list();
55 | try {
56 | while (cursor.moveToNext()) {
57 | String title = cursor.getString(cursor.getColumnIndex(FavDB.ITEM_TITLE));
58 | String id = cursor.getString(cursor.getColumnIndex(FavDB.KEY_ID));
59 | int image = Integer.parseInt(cursor.getString(cursor.getColumnIndex(FavDB.ITEM_IMAGE)));
60 | FavItem favItem = new FavItem(title, id, image);
61 | favItemList.add(favItem);
62 | }
63 | } finally {
64 | if (cursor != null && cursor.isClosed())
65 | cursor.close();
66 | db.close();
67 | }
68 |
69 | favAdapter = new FavAdapter(getActivity(), favItemList);
70 |
71 | recyclerView.setAdapter(favAdapter);
72 |
73 | }
74 |
75 | // remove item after swipe
76 | private ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
77 | @Override
78 | public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
79 | return false;
80 | }
81 |
82 | @Override
83 | public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
84 | final int position = viewHolder.getAdapterPosition(); // get position which is swipe
85 | final FavItem favItem = favItemList.get(position);
86 | if (direction == ItemTouchHelper.LEFT) { //if swipe left
87 | favAdapter.notifyItemRemoved(position); // item removed from recyclerview
88 | favItemList.remove(position); //then remove item
89 | favDB.remove_fav(favItem.getKey_id()); // remove item from database
90 | }
91 | }
92 | };
93 |
94 | }
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Adapters/FavAdapter.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Adapters;
2 |
3 | import android.content.Context;
4 | import android.os.Handler;
5 | import android.os.Looper;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import androidx.annotation.NonNull;
14 | import androidx.annotation.Nullable;
15 | import androidx.recyclerview.widget.RecyclerView;
16 |
17 | import com.google.firebase.database.DataSnapshot;
18 | import com.google.firebase.database.DatabaseError;
19 | import com.google.firebase.database.DatabaseReference;
20 | import com.google.firebase.database.FirebaseDatabase;
21 | import com.google.firebase.database.MutableData;
22 | import com.google.firebase.database.Transaction;
23 |
24 | import java.util.List;
25 |
26 | import ru.embersoft.favoritelist.Helpers.FavDB;
27 | import ru.embersoft.favoritelist.Helpers.FavItem;
28 | import ru.embersoft.favoritelist.R;
29 |
30 | public class FavAdapter extends RecyclerView.Adapter {
31 |
32 | private Context context;
33 | private List favItemList;
34 | private FavDB favDB;
35 | private DatabaseReference refLike;
36 |
37 | public FavAdapter(Context context, List favItemList) {
38 | this.context = context;
39 | this.favItemList = favItemList;
40 | }
41 |
42 | @NonNull
43 | @Override
44 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
45 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fav_item,
46 | parent, false);
47 | favDB = new FavDB(context);
48 | return new ViewHolder(view);
49 | }
50 |
51 | @Override
52 | public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
53 | holder.favTextView.setText(favItemList.get(position).getItem_title());
54 | holder.favImageView.setImageResource(favItemList.get(position).getItem_image());
55 | }
56 |
57 | @Override
58 | public int getItemCount() {
59 | return favItemList.size();
60 | }
61 |
62 | public class ViewHolder extends RecyclerView.ViewHolder {
63 |
64 | TextView favTextView;
65 | Button favBtn;
66 | ImageView favImageView;
67 |
68 | public ViewHolder(@NonNull View itemView) {
69 | super(itemView);
70 | favTextView = itemView.findViewById(R.id.favTextView);
71 | favBtn = itemView.findViewById(R.id.favBtn);
72 | favImageView = itemView.findViewById(R.id.favImageView);
73 |
74 | refLike = FirebaseDatabase.getInstance().getReference().child("likes");
75 | //remove from fav after click
76 | favBtn.setOnClickListener(new View.OnClickListener() {
77 | @Override
78 | public void onClick(View view) {
79 | int position = getAdapterPosition();
80 | final FavItem favItem = favItemList.get(position);
81 | final DatabaseReference upvotesRefLike = refLike.child(favItemList.get(position).getKey_id());
82 | favDB.remove_fav(favItem.getKey_id());
83 | removeItem(position);
84 |
85 | upvotesRefLike.runTransaction(new Transaction.Handler() {
86 | @NonNull
87 | @Override
88 | public Transaction.Result doTransaction(@NonNull final MutableData mutableData) {
89 | try {
90 | Integer currentValue = mutableData.getValue(Integer.class);
91 | if (currentValue == null) {
92 | mutableData.setValue(1);
93 | } else {
94 | mutableData.setValue(currentValue - 1);
95 | }
96 | } catch (Exception e) {
97 | throw e;
98 | }
99 | return Transaction.success(mutableData);
100 | }
101 |
102 | @Override
103 | public void onComplete(@Nullable DatabaseError databaseError, boolean b, @Nullable DataSnapshot dataSnapshot) {
104 | System.out.println("Transaction completed");
105 | }
106 | });
107 | }
108 | });
109 | }
110 | }
111 |
112 | private void removeItem(int position) {
113 | favItemList.remove(position);
114 | notifyItemRemoved(position);
115 | notifyItemRangeChanged(position,favItemList.size());
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/ru/embersoft/favoritelist/Adapters/CoffeeAdapter.java:
--------------------------------------------------------------------------------
1 | package ru.embersoft.favoritelist.Adapters;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.os.Handler;
8 | import android.os.Looper;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.Button;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import androidx.annotation.NonNull;
17 | import androidx.annotation.Nullable;
18 | import androidx.recyclerview.widget.RecyclerView;
19 |
20 | import com.google.firebase.database.DataSnapshot;
21 | import com.google.firebase.database.DatabaseError;
22 | import com.google.firebase.database.DatabaseReference;
23 | import com.google.firebase.database.FirebaseDatabase;
24 | import com.google.firebase.database.MutableData;
25 | import com.google.firebase.database.Transaction;
26 |
27 | import java.util.ArrayList;
28 |
29 | import ru.embersoft.favoritelist.Helpers.CoffeeItem;
30 | import ru.embersoft.favoritelist.Helpers.FavDB;
31 | import ru.embersoft.favoritelist.R;
32 |
33 | public class CoffeeAdapter extends RecyclerView.Adapter {
34 |
35 | private ArrayList coffeeItems;
36 | private Context context;
37 | private FavDB favDB;
38 |
39 | public CoffeeAdapter(ArrayList coffeeItems, Context context) {
40 | this.coffeeItems = coffeeItems;
41 | this.context = context;
42 | }
43 |
44 | @NonNull
45 | @Override
46 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
47 | favDB = new FavDB(context);
48 | //create table on first
49 | SharedPreferences prefs = context.getSharedPreferences("prefs", Context.MODE_PRIVATE);
50 | boolean firstStart = prefs.getBoolean("firstStart", true);
51 | if (firstStart) {
52 | createTableOnFirstStart();
53 | }
54 |
55 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item,
56 | parent,false);
57 | return new ViewHolder(view);
58 | }
59 |
60 |
61 |
62 | @Override
63 | public void onBindViewHolder(@NonNull CoffeeAdapter.ViewHolder holder, int position) {
64 | final CoffeeItem coffeeItem = coffeeItems.get(position);
65 |
66 | readCursorData(coffeeItem, holder);
67 | holder.imageView.setImageResource(coffeeItem.getImageResourse());
68 | holder.titleTextView.setText(coffeeItem.getTitle());
69 | }
70 |
71 |
72 |
73 | @Override
74 | public int getItemCount() {
75 | return coffeeItems.size();
76 | }
77 |
78 | public class ViewHolder extends RecyclerView.ViewHolder {
79 |
80 | ImageView imageView;
81 | TextView titleTextView, likeCountTextView;
82 | Button favBtn;
83 |
84 | public ViewHolder(@NonNull View itemView) {
85 | super(itemView);
86 |
87 | imageView = itemView.findViewById(R.id.imageView);
88 | titleTextView = itemView.findViewById(R.id.titleTextView);
89 | favBtn = itemView.findViewById(R.id.favBtn);
90 | likeCountTextView = itemView.findViewById(R.id.likeCountTextView);
91 |
92 | //add to fav btn
93 | favBtn.setOnClickListener(new View.OnClickListener() {
94 | @Override
95 | public void onClick(View view) {
96 | int position = getAdapterPosition();
97 | CoffeeItem coffeeItem = coffeeItems.get(position);
98 |
99 | likeClick(coffeeItem, favBtn, likeCountTextView);
100 | }
101 | });
102 | }
103 | }
104 |
105 | private void createTableOnFirstStart() {
106 | favDB.insertEmpty();
107 |
108 | SharedPreferences prefs = context.getSharedPreferences("prefs", Context.MODE_PRIVATE);
109 | SharedPreferences.Editor editor = prefs.edit();
110 | editor.putBoolean("firstStart", false);
111 | editor.apply();
112 | }
113 |
114 | private void readCursorData(CoffeeItem coffeeItem, ViewHolder viewHolder) {
115 | Cursor cursor = favDB.read_all_data(coffeeItem.getKey_id());
116 | SQLiteDatabase db = favDB.getReadableDatabase();
117 | try {
118 | while (cursor.moveToNext()) {
119 | String item_fav_status = cursor.getString(cursor.getColumnIndex(FavDB.FAVORITE_STATUS));
120 | coffeeItem.setFavStatus(item_fav_status);
121 |
122 | //check fav status
123 | if (item_fav_status != null && item_fav_status.equals("1")) {
124 | viewHolder.favBtn.setBackgroundResource(R.drawable.ic_favorite_red_24dp);
125 | } else if (item_fav_status != null && item_fav_status.equals("0")) {
126 | viewHolder.favBtn.setBackgroundResource(R.drawable.ic_favorite_shadow_24dp);
127 | }
128 | }
129 | } finally {
130 | if (cursor != null && cursor.isClosed())
131 | cursor.close();
132 | db.close();
133 | }
134 |
135 | }
136 |
137 | // like click
138 | private void likeClick (CoffeeItem coffeeItem, Button favBtn, final TextView textLike) {
139 | DatabaseReference refLike = FirebaseDatabase.getInstance().getReference().child("likes");
140 | final DatabaseReference upvotesRefLike = refLike.child(coffeeItem.getKey_id());
141 |
142 | if (coffeeItem.getFavStatus().equals("0")) {
143 |
144 | coffeeItem.setFavStatus("1");
145 | favDB.insertIntoTheDatabase(coffeeItem.getTitle(), coffeeItem.getImageResourse(),
146 | coffeeItem.getKey_id(), coffeeItem.getFavStatus());
147 | favBtn.setBackgroundResource(R.drawable.ic_favorite_red_24dp);
148 | favBtn.setSelected(true);
149 |
150 | upvotesRefLike.runTransaction(new Transaction.Handler() {
151 | @NonNull
152 | @Override
153 | public Transaction.Result doTransaction(@NonNull final MutableData mutableData) {
154 | try {
155 | Integer currentValue = mutableData.getValue(Integer.class);
156 | if (currentValue == null) {
157 | mutableData.setValue(1);
158 | } else {
159 | mutableData.setValue(currentValue + 1);
160 | new Handler(Looper.getMainLooper()).post(new Runnable() {
161 | @Override
162 | public void run() {
163 | textLike.setText(mutableData.getValue().toString());
164 | }
165 | });
166 | }
167 | } catch (Exception e) {
168 | throw e;
169 | }
170 | return Transaction.success(mutableData);
171 | }
172 |
173 | @Override
174 | public void onComplete(@Nullable DatabaseError databaseError, boolean b, @Nullable DataSnapshot dataSnapshot) {
175 | System.out.println("Transaction completed");
176 | }
177 | });
178 |
179 |
180 |
181 | } else if (coffeeItem.getFavStatus().equals("1")) {
182 | coffeeItem.setFavStatus("0");
183 | favDB.remove_fav(coffeeItem.getKey_id());
184 | favBtn.setBackgroundResource(R.drawable.ic_favorite_shadow_24dp);
185 | favBtn.setSelected(false);
186 |
187 | upvotesRefLike.runTransaction(new Transaction.Handler() {
188 | @NonNull
189 | @Override
190 | public Transaction.Result doTransaction(@NonNull final MutableData mutableData) {
191 | try {
192 | Integer currentValue = mutableData.getValue(Integer.class);
193 | if (currentValue == null) {
194 | mutableData.setValue(1);
195 | } else {
196 | mutableData.setValue(currentValue - 1);
197 | new Handler(Looper.getMainLooper()).post(new Runnable() {
198 | @Override
199 | public void run() {
200 | textLike.setText(mutableData.getValue().toString());
201 | }
202 | });
203 | }
204 | } catch (Exception e) {
205 | throw e;
206 | }
207 | return Transaction.success(mutableData);
208 | }
209 |
210 | @Override
211 | public void onComplete(@Nullable DatabaseError databaseError, boolean b, @Nullable DataSnapshot dataSnapshot) {
212 | System.out.println("Transaction completed");
213 | }
214 | });
215 | }
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 | }
226 | }
227 |
--------------------------------------------------------------------------------