├── .gitignore
├── LICENSE
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── pl
│ │ └── droidsonroids
│ │ └── examplerealmmvp
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── pl
│ │ │ └── droidsonroids
│ │ │ └── examplerealmmvp
│ │ │ ├── ApplicationModule.java
│ │ │ ├── BooksApplication.java
│ │ │ ├── model
│ │ │ ├── Author.java
│ │ │ ├── Book.java
│ │ │ ├── Publisher.java
│ │ │ └── realm
│ │ │ │ └── RealmService.java
│ │ │ └── ui
│ │ │ ├── BaseActivity.java
│ │ │ ├── BasePresenter.java
│ │ │ ├── adapter
│ │ │ ├── BookGridAdapter.java
│ │ │ └── BookListAdapter.java
│ │ │ ├── add
│ │ │ ├── AddBookActivity.java
│ │ │ ├── AddBookModule.java
│ │ │ ├── AddBookPresenter.java
│ │ │ ├── AddBookPresenterImpl.java
│ │ │ └── AddBookView.java
│ │ │ ├── author
│ │ │ ├── AuthorActivity.java
│ │ │ ├── AuthorModule.java
│ │ │ ├── AuthorPresenter.java
│ │ │ ├── AuthorPresenterImpl.java
│ │ │ └── AuthorView.java
│ │ │ ├── books
│ │ │ ├── BooksActivity.java
│ │ │ ├── BooksModule.java
│ │ │ ├── BooksPresenter.java
│ │ │ ├── BooksPresenterImpl.java
│ │ │ └── BooksView.java
│ │ │ ├── detail
│ │ │ ├── DetailActivity.java
│ │ │ ├── DetailModule.java
│ │ │ ├── DetailPresenter.java
│ │ │ ├── DetailPresenterImpl.java
│ │ │ └── DetailView.java
│ │ │ └── publisher
│ │ │ ├── PublisherActivity.java
│ │ │ ├── PublisherModule.java
│ │ │ ├── PublisherPresenter.java
│ │ │ ├── PublisherPresenterImpl.java
│ │ │ └── PublisherView.java
│ └── res
│ │ ├── drawable-hdpi
│ │ └── ic_add_white_24dp.png
│ │ ├── drawable-mdpi
│ │ └── ic_add_white_24dp.png
│ │ ├── drawable-xhdpi
│ │ └── ic_add_white_24dp.png
│ │ ├── drawable-xxhdpi
│ │ └── ic_add_white_24dp.png
│ │ ├── drawable-xxxhdpi
│ │ └── ic_add_white_24dp.png
│ │ ├── drawable
│ │ └── layout_cover_normal.xml
│ │ ├── layout
│ │ ├── activity_add_book.xml
│ │ ├── activity_author.xml
│ │ ├── activity_main.xml
│ │ ├── activity_my_detail.xml
│ │ ├── activity_publisher.xml
│ │ ├── content_main.xml
│ │ ├── item_book.xml
│ │ └── item_publisher_book.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-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── pl
│ └── droidsonroids
│ └── examplerealmmvp
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Droids On Roids
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'realm-android'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.2"
7 |
8 | defaultConfig {
9 | applicationId "pl.droidsonroids.examplerealmmvp"
10 | minSdkVersion 16
11 | targetSdkVersion 23
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | packagingOptions {
22 | exclude 'META-INF/services/javax.annotation.processing.Processor'
23 | exclude 'META-INF/maven/com.squareup/javawriter/pom.xml'
24 | exclude 'META-INF/maven/com.squareup/javawriter/pom.properties'
25 | }
26 | }
27 |
28 | dependencies {
29 | compile 'com.android.support:appcompat-v7:23.1.1'
30 | compile 'com.android.support:design:23.1.1'
31 | compile 'com.jakewharton:butterknife:7.0.1'
32 | compile 'com.squareup.dagger:dagger:1.2.1'
33 | compile 'com.squareup.dagger:dagger-compiler:1.2.1'
34 |
35 | compile fileTree(dir: 'libs', include: ['*.jar'])
36 |
37 | testCompile 'junit:junit:4.12'
38 | }
39 |
--------------------------------------------------------------------------------
/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 /home/droidsonroids/android-sdks/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 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/pl/droidsonroids/examplerealmmvp/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp;
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/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
28 |
31 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ApplicationModule.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import io.realm.Realm;
6 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
7 |
8 | @Module(injects = BooksApplication.class, library = true)
9 | public class ApplicationModule {
10 |
11 | public ApplicationModule() {}
12 |
13 | @Provides
14 | Realm provideRealm() {
15 | return Realm.getDefaultInstance();
16 | }
17 |
18 | @Provides
19 | RealmService provideRealmService(final Realm realm) {
20 | return new RealmService(realm);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/BooksApplication.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp;
2 |
3 | import android.app.Application;
4 | import android.support.annotation.NonNull;
5 | import dagger.ObjectGraph;
6 | import io.realm.Realm;
7 | import io.realm.RealmConfiguration;
8 |
9 | public class BooksApplication extends Application {
10 |
11 | private static BooksApplication sInstance;
12 | private ObjectGraph mApplicationGraph;
13 |
14 | @Override
15 | public void onCreate() {
16 | super.onCreate();
17 |
18 | sInstance = this;
19 | initRealmConfiguration();
20 | initApplicationGraph();
21 | }
22 |
23 | private void initRealmConfiguration() {
24 | RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this)
25 | .deleteRealmIfMigrationNeeded()
26 | .build();
27 | Realm.setDefaultConfiguration(realmConfiguration);
28 | }
29 |
30 | private void initApplicationGraph() {
31 | mApplicationGraph = ObjectGraph.create(new ApplicationModule());
32 | }
33 |
34 | public static void injectModules(@NonNull final Object object, final Object... modules) {
35 | sInstance.mApplicationGraph.plus(modules).inject(object);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Author.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.model;
2 |
3 | import io.realm.RealmList;
4 | import io.realm.RealmObject;
5 | import io.realm.annotations.PrimaryKey;
6 |
7 | public class Author extends RealmObject {
8 |
9 | @PrimaryKey
10 | private int id;
11 |
12 | private String name;
13 | private String lastname;
14 | private RealmList books;
15 |
16 | public int getId() {
17 | return id;
18 | }
19 |
20 | public void setId(final int id) {
21 | this.id = id;
22 | }
23 |
24 | public String getName() {
25 | return name;
26 | }
27 |
28 | public void setName(final String name) {
29 | this.name = name;
30 | }
31 |
32 | public String getLastname() {
33 | return lastname;
34 | }
35 |
36 | public void setLastname(final String lastname) {
37 | this.lastname = lastname;
38 | }
39 |
40 | public RealmList getBooks() {
41 | return books;
42 | }
43 |
44 | public void setBooks(final RealmList books) {
45 | this.books = books;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Book.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.model;
2 |
3 | import io.realm.RealmObject;
4 | import io.realm.annotations.PrimaryKey;
5 |
6 | public class Book extends RealmObject {
7 |
8 | @PrimaryKey
9 | private int id;
10 |
11 | private String isbn;
12 | private String title;
13 | private Author author;
14 | private Publisher publisher;
15 |
16 | public int getId() {
17 | return id;
18 | }
19 |
20 | public void setId(final int id) {
21 | this.id = id;
22 | }
23 |
24 | public String getIsbn() {
25 | return isbn;
26 | }
27 |
28 | public void setIsbn(final String isbn) {
29 | this.isbn = isbn;
30 | }
31 |
32 | public String getTitle() {
33 | return title;
34 | }
35 |
36 | public void setTitle(final String title) {
37 | this.title = title;
38 | }
39 |
40 | public Author getAuthor() {
41 | return author;
42 | }
43 |
44 | public void setAuthor(final Author author) {
45 | this.author = author;
46 | }
47 |
48 | public Publisher getPublisher() {
49 | return publisher;
50 | }
51 |
52 | public void setPublisher(final Publisher publisher) {
53 | this.publisher = publisher;
54 | }
55 |
56 | public String getDetails() {
57 | String details = "";
58 | details += getAuthorFullName();
59 | details += " | ";
60 | details += getPublisher().getName();
61 | return details;
62 | }
63 |
64 | public String getAuthorFullName() {
65 | return String.format("%s %s", getAuthor().getName(), getAuthor().getLastname());
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Publisher.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.model;
2 |
3 | import io.realm.RealmList;
4 | import io.realm.RealmObject;
5 | import io.realm.annotations.PrimaryKey;
6 |
7 | public class Publisher extends RealmObject {
8 |
9 | @PrimaryKey
10 | private int id;
11 |
12 | private String name;
13 | private RealmList books;
14 |
15 | public int getId() {
16 | return id;
17 | }
18 |
19 | public void setId(final int id) {
20 | this.id = id;
21 | }
22 |
23 | public String getName() {
24 | return name;
25 | }
26 |
27 | public void setName(final String name) {
28 | this.name = name;
29 | }
30 |
31 | public RealmList getBooks() {
32 | return books;
33 | }
34 |
35 | public void setBooks(final RealmList books) {
36 | this.books = books;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/model/realm/RealmService.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.model.realm;
2 |
3 | import io.realm.Realm;
4 | import io.realm.RealmList;
5 | import io.realm.RealmResults;
6 | import pl.droidsonroids.examplerealmmvp.model.Author;
7 | import pl.droidsonroids.examplerealmmvp.model.Book;
8 | import pl.droidsonroids.examplerealmmvp.model.Publisher;
9 |
10 | public class RealmService {
11 |
12 | private final Realm mRealm;
13 |
14 | public RealmService(final Realm realm) {
15 | mRealm = realm;
16 | }
17 |
18 | public void closeRealm() {
19 | mRealm.close();
20 | }
21 |
22 | public RealmResults getAllBooks() {
23 | return mRealm.allObjects(Book.class);
24 | }
25 |
26 | public Book getBook(final int bookId) {
27 | return mRealm.where(Book.class).equalTo("id", bookId).findFirst();
28 | }
29 |
30 | public RealmList getPublisherBooks(final String publisher) {
31 | Publisher foundPublisher = getPublisher(publisher, mRealm);
32 | return foundPublisher == null ? new RealmList() : foundPublisher.getBooks();
33 | }
34 |
35 | public RealmList getAuthorBooks(final String author) {
36 | Author foundAuthor = getAuthor(splitAuthorName(author), mRealm);
37 | return foundAuthor == null ? new RealmList() : foundAuthor.getBooks();
38 | }
39 |
40 | public void addBookAsync(final String title, final String author, final String isbn, final String publisher,
41 | final OnTransactionCallback onTransactionCallback) {
42 | mRealm.executeTransaction(new Realm.Transaction() {
43 | @Override
44 | public void execute(final Realm realm) {
45 | Book book = realm.createObject(Book.class);
46 | book.setId(realm.allObjects(Book.class).size());
47 | book.setTitle(title);
48 | book.setAuthor(createOrGetAuthor(author, book, realm));
49 | book.setPublisher(createOrGetPublisher(publisher, book, realm));
50 | book.setIsbn(isbn);
51 | }
52 | }, new Realm.Transaction.Callback() {
53 |
54 | @Override
55 | public void onSuccess() {
56 | if (onTransactionCallback != null) {
57 | onTransactionCallback.onRealmSuccess();
58 | }
59 | }
60 |
61 | @Override
62 | public void onError(final Exception e) {
63 | if (onTransactionCallback != null) {
64 | onTransactionCallback.onRealmError(e);
65 | }
66 | }
67 | });
68 | }
69 |
70 | private Author createOrGetAuthor(final String author, final Book book, final Realm realm) {
71 | String[] authorName = splitAuthorName(author);
72 | Author foundAuthor = getAuthor(authorName, realm);
73 | if(foundAuthor == null) {
74 | foundAuthor = addAuthor(authorName, realm);
75 | }
76 | foundAuthor.getBooks().add(book);
77 | return foundAuthor;
78 | }
79 |
80 | private Author addAuthor(final String[] authorName, final Realm realm) {
81 | Author author = realm.createObject(Author.class);
82 | author.setId(realm.allObjects(Author.class).size());
83 | author.setName(authorName[0]);
84 | author.setLastname(authorName[1]);
85 | return author;
86 | }
87 |
88 | private Publisher createOrGetPublisher(final String publisher, final Book book, final Realm realm) {
89 | Publisher foundPublisher = getPublisher(publisher, realm);
90 | if(foundPublisher == null) {
91 | foundPublisher = addPublisher(publisher, realm);
92 | }
93 | foundPublisher.getBooks().add(book);
94 | return foundPublisher;
95 | }
96 |
97 | private Publisher addPublisher(final String publisherName, final Realm realm) {
98 | Publisher publisher = realm.createObject(Publisher.class);
99 | publisher.setId(realm.allObjects(Publisher.class).size());
100 | publisher.setName(publisherName);
101 | return publisher;
102 | }
103 |
104 | private Author getAuthor(final String[] authorName, final Realm realm) {
105 | return realm.where(Author.class).equalTo("name", authorName[0]).equalTo("lastname", authorName[1]).findFirst();
106 | }
107 |
108 | private String[] splitAuthorName(final String author) {
109 | return author.split(" ");
110 | }
111 |
112 | private Publisher getPublisher(final String publisher, final Realm realm) {
113 | return realm.where(Publisher.class).equalTo("name", publisher).findFirst();
114 | }
115 |
116 | public interface OnTransactionCallback {
117 | void onRealmSuccess();
118 | void onRealmError(final Exception e);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import pl.droidsonroids.examplerealmmvp.BooksApplication;
6 |
7 | public abstract class BaseActivity extends AppCompatActivity {
8 |
9 | @Override
10 | public void onCreate(final Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | BooksApplication.injectModules(this, getModule());
13 | }
14 |
15 | @Override
16 | protected void onDestroy() {
17 | closeRealm();
18 | super.onDestroy();
19 | }
20 |
21 | protected abstract Object getModule();
22 | protected abstract void closeRealm();
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui;
2 |
3 | public interface BasePresenter {
4 | void setView(T view);
5 | void clearView();
6 | void closeRealm();
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/adapter/BookGridAdapter.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.adapter;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 | import butterknife.Bind;
9 | import butterknife.ButterKnife;
10 | import io.realm.RealmList;
11 | import pl.droidsonroids.examplerealmmvp.R;
12 | import pl.droidsonroids.examplerealmmvp.model.Book;
13 |
14 | public class BookGridAdapter extends RecyclerView.Adapter {
15 |
16 | private RealmList mBooks;
17 |
18 | @Override
19 | public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
20 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_publisher_book, parent, false);
21 | return new ViewHolder(view);
22 | }
23 |
24 | @Override
25 | public void onBindViewHolder(final ViewHolder holder, final int position) {
26 | holder.mTextTitle.setText(mBooks.get(position).getTitle());
27 | }
28 |
29 | @Override
30 | public int getItemCount() {
31 | return mBooks.size();
32 | }
33 |
34 | public void setBooks(final RealmList books) {
35 | mBooks = books;
36 | notifyDataSetChanged();
37 | }
38 |
39 | public class ViewHolder extends RecyclerView.ViewHolder {
40 |
41 | @Bind(R.id.text_title) TextView mTextTitle;
42 |
43 | public ViewHolder(final View itemView) {
44 | super(itemView);
45 | ButterKnife.bind(this, itemView);
46 | }
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/adapter/BookListAdapter.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.adapter;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.LinearLayout;
8 | import android.widget.TextView;
9 | import butterknife.Bind;
10 | import butterknife.ButterKnife;
11 | import io.realm.RealmChangeListener;
12 | import io.realm.RealmResults;
13 | import pl.droidsonroids.examplerealmmvp.R;
14 | import pl.droidsonroids.examplerealmmvp.model.Book;
15 |
16 | public class BookListAdapter extends RecyclerView.Adapter implements RealmChangeListener {
17 |
18 | private RealmResults mBooks;
19 | private OnBookClickListener mOnBookClickListener;
20 |
21 | public BookListAdapter() {}
22 |
23 | @Override
24 | public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
25 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_book, parent, false);
26 | return new ViewHolder(view);
27 | }
28 |
29 | @Override
30 | public void onBindViewHolder(final ViewHolder holder, final int position) {
31 | final Book book = mBooks.get(position);
32 |
33 | holder.mTextTitle.setText(book.getTitle());
34 | holder.mTextDetails.setText(book.getDetails());
35 | holder.mLayoutItem.setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(final View v) {
38 | if (mOnBookClickListener != null) {
39 | mOnBookClickListener.onBookClick(book.getId());
40 | }
41 | }
42 | });
43 | }
44 |
45 | @Override
46 | public int getItemCount() {
47 | return mBooks.size();
48 | }
49 |
50 | @Override
51 | public void onChange() {
52 | notifyDataSetChanged();
53 | }
54 |
55 | public void setOnBookClickListener(final OnBookClickListener onBookClickListener) {
56 | mOnBookClickListener = onBookClickListener;
57 | }
58 |
59 | public void setBooks(final RealmResults books) {
60 | mBooks = books;
61 | mBooks.addChangeListener(this);
62 | notifyDataSetChanged();
63 | }
64 |
65 | public class ViewHolder extends RecyclerView.ViewHolder {
66 |
67 | @Bind(R.id.layout_item_container) LinearLayout mLayoutItem;
68 | @Bind(R.id.text_title) TextView mTextTitle;
69 | @Bind(R.id.text_details) TextView mTextDetails;
70 |
71 | public ViewHolder(final View itemView) {
72 | super(itemView);
73 | ButterKnife.bind(this, itemView);
74 | }
75 | }
76 |
77 | public interface OnBookClickListener {
78 | void onBookClick(int id);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/add/AddBookActivity.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.add;
2 |
3 | import android.support.design.widget.Snackbar;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.widget.EditText;
7 | import android.widget.LinearLayout;
8 | import butterknife.Bind;
9 | import butterknife.ButterKnife;
10 | import butterknife.OnClick;
11 | import javax.inject.Inject;
12 | import pl.droidsonroids.examplerealmmvp.BooksApplication;
13 | import pl.droidsonroids.examplerealmmvp.R;
14 | import pl.droidsonroids.examplerealmmvp.ui.BaseActivity;
15 |
16 | public class AddBookActivity extends BaseActivity implements AddBookView {
17 |
18 | @Bind(R.id.layout_container) LinearLayout mLayoutContainer;
19 | @Bind(R.id.edit_title) EditText mEditTitle;
20 | @Bind(R.id.edit_author) EditText mEditAuthor;
21 | @Bind(R.id.edit_isbn) EditText mEditIsbn;
22 | @Bind(R.id.edit_publisher) EditText mEditPublisher;
23 |
24 | @Inject AddBookPresenter mAddBookPresenter;
25 |
26 | @Override
27 | public void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_add_book);
30 | ButterKnife.bind(this);
31 | }
32 |
33 | @Override
34 | protected Object getModule() {
35 | return new AddBookModule();
36 | }
37 |
38 | @Override
39 | protected void onStart() {
40 | super.onStart();
41 | mAddBookPresenter.setView(this);
42 | }
43 |
44 | @Override
45 | protected void onStop() {
46 | super.onStop();
47 | mAddBookPresenter.clearView();
48 | }
49 |
50 | @Override
51 | protected void closeRealm() {
52 | mAddBookPresenter.closeRealm();
53 | }
54 |
55 | @OnClick(R.id.button_add)
56 | public void onAddClick() {
57 | mAddBookPresenter.onAddClick(
58 | mEditTitle.getText().toString(),
59 | mEditAuthor.getText().toString(),
60 | mEditIsbn.getText().toString(),
61 | mEditPublisher.getText().toString());
62 | }
63 |
64 | @Override
65 | public void showAddBookError() {
66 | Snackbar.make(mLayoutContainer, R.string.add_new_book_error, Snackbar.LENGTH_SHORT).show();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/add/AddBookModule.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.add;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import pl.droidsonroids.examplerealmmvp.ApplicationModule;
6 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
7 |
8 | @Module(injects = AddBookActivity.class, addsTo = ApplicationModule.class)
9 | public class AddBookModule {
10 |
11 | @Provides
12 | AddBookPresenter provideAddBookPresenter(final RealmService realmService) {
13 | return new AddBookPresenterImpl(realmService);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/add/AddBookPresenter.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.add;
2 |
3 | import pl.droidsonroids.examplerealmmvp.ui.BasePresenter;
4 |
5 | public interface AddBookPresenter extends BasePresenter {
6 | void onAddClick(String title, String author, String isbn, final String publisher);
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/add/AddBookPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.add;
2 |
3 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
4 |
5 | public class AddBookPresenterImpl implements AddBookPresenter, RealmService.OnTransactionCallback {
6 |
7 | private final RealmService mRealmService;
8 | private AddBookView mAddBookView = new AddBookView.EmptyAddBookView();
9 |
10 | public AddBookPresenterImpl(final RealmService realmService) {
11 | mRealmService = realmService;
12 | }
13 |
14 | @Override
15 | public void setView(final AddBookView view) {
16 | mAddBookView = view;
17 | }
18 |
19 | @Override
20 | public void clearView() {
21 | mAddBookView = new AddBookView.EmptyAddBookView();
22 | }
23 |
24 | @Override
25 | public void closeRealm() {
26 | mRealmService.closeRealm();
27 | }
28 |
29 | @Override
30 | public void onAddClick(final String title, final String author, final String isbn, final String publisher) {
31 | mRealmService.addBookAsync(title, author, isbn, publisher, this);
32 | }
33 |
34 | @Override
35 | public void onRealmSuccess() {
36 | mAddBookView.finish();
37 | }
38 |
39 | @Override
40 | public void onRealmError(final Exception e) {
41 | e.printStackTrace();
42 | mAddBookView.showAddBookError();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/add/AddBookView.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.add;
2 |
3 | public interface AddBookView {
4 | void finish();
5 | void showAddBookError();
6 |
7 | class EmptyAddBookView implements AddBookView {
8 |
9 | @Override
10 | public void finish() {
11 |
12 | }
13 |
14 | @Override
15 | public void showAddBookError() {
16 |
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/author/AuthorActivity.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.author;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 | import android.support.v7.widget.GridLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import butterknife.Bind;
10 | import butterknife.ButterKnife;
11 | import io.realm.RealmList;
12 | import javax.inject.Inject;
13 | import pl.droidsonroids.examplerealmmvp.BooksApplication;
14 | import pl.droidsonroids.examplerealmmvp.R;
15 | import pl.droidsonroids.examplerealmmvp.model.Book;
16 | import pl.droidsonroids.examplerealmmvp.ui.BaseActivity;
17 | import pl.droidsonroids.examplerealmmvp.ui.adapter.BookGridAdapter;
18 |
19 | public class AuthorActivity extends BaseActivity implements AuthorView {
20 |
21 | private static final String EXTRA_AUTHOR = "EXTRA_AUTHOR";
22 |
23 | @Bind(R.id.recycler_view) RecyclerView mRecyclerView;
24 | @Inject AuthorPresenter mAuthorPresenter;
25 | private BookGridAdapter mAdapter;
26 |
27 | public static Intent getStartIntent(final Context context, final String author) {
28 | Intent intent = new Intent(context, AuthorActivity.class);
29 | intent.putExtra(EXTRA_AUTHOR, author);
30 | return intent;
31 | }
32 |
33 | @Override
34 | public void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_author);
37 | ButterKnife.bind(this);
38 |
39 | initList();
40 | }
41 |
42 | @Override
43 | protected Object getModule() {
44 | return new AuthorModule(getIntent().getExtras().getString(EXTRA_AUTHOR));
45 | }
46 |
47 | private void initList() {
48 | mAdapter = new BookGridAdapter();
49 | mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
50 | mRecyclerView.setAdapter(mAdapter);
51 | }
52 |
53 | @Override
54 | protected void onStart() {
55 | super.onStart();
56 | mAuthorPresenter.setView(this);
57 | }
58 |
59 | @Override
60 | protected void onStop() {
61 | super.onStop();
62 | mAuthorPresenter.clearView();
63 | }
64 |
65 | @Override
66 | protected void closeRealm() {
67 | mAuthorPresenter.closeRealm();
68 | }
69 |
70 | @Override
71 | public void showBooks(final RealmList books) {
72 | mAdapter.setBooks(books);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/author/AuthorModule.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.author;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import pl.droidsonroids.examplerealmmvp.ApplicationModule;
6 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
7 | import pl.droidsonroids.examplerealmmvp.ui.publisher.PublisherActivity;
8 |
9 | @Module(injects = AuthorActivity.class, addsTo = ApplicationModule.class)
10 | public class AuthorModule {
11 |
12 | private final String mAuthor;
13 |
14 | public AuthorModule(final String author) {
15 | mAuthor = author;
16 | }
17 |
18 | @Provides
19 | AuthorPresenter provideAuthorPresenter(final RealmService realmService) {
20 | return new AuthorPresenterImpl(realmService, mAuthor);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/author/AuthorPresenter.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.author;
2 |
3 | import pl.droidsonroids.examplerealmmvp.ui.BasePresenter;
4 |
5 | public interface AuthorPresenter extends BasePresenter {
6 | }
7 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/author/AuthorPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.author;
2 |
3 | import io.realm.RealmList;
4 | import pl.droidsonroids.examplerealmmvp.model.Book;
5 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
6 |
7 | public class AuthorPresenterImpl implements AuthorPresenter {
8 |
9 | private final RealmService mRealmService;
10 | private final String mAuthor;
11 | private AuthorView mAuthorView = new AuthorView.EmptyAuthorView();
12 |
13 | public AuthorPresenterImpl(final RealmService realmService, final String author) {
14 | mRealmService = realmService;
15 | mAuthor = author;
16 | }
17 |
18 | @Override
19 | public void setView(final AuthorView view) {
20 | mAuthorView = view;
21 | mAuthorView.showBooks(formatBooks(mRealmService.getAuthorBooks(mAuthor)));
22 | }
23 |
24 | private RealmList formatBooks(final RealmList publisherBooks) {
25 | return publisherBooks;
26 | }
27 |
28 | @Override
29 | public void clearView() {
30 | mAuthorView = new AuthorView.EmptyAuthorView();
31 | }
32 |
33 | @Override
34 | public void closeRealm() {
35 | mRealmService.closeRealm();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/author/AuthorView.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.author;
2 |
3 | import io.realm.RealmList;
4 | import pl.droidsonroids.examplerealmmvp.model.Book;
5 |
6 | public interface AuthorView {
7 |
8 | void showBooks(RealmList books);
9 |
10 | class EmptyAuthorView implements AuthorView {
11 |
12 | @Override
13 | public void showBooks(final RealmList books) {
14 |
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/books/BooksActivity.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.books;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.support.v7.widget.Toolbar;
8 | import butterknife.Bind;
9 | import butterknife.ButterKnife;
10 | import butterknife.OnClick;
11 | import io.realm.RealmResults;
12 | import javax.inject.Inject;
13 | import pl.droidsonroids.examplerealmmvp.R;
14 | import pl.droidsonroids.examplerealmmvp.model.Book;
15 | import pl.droidsonroids.examplerealmmvp.ui.BaseActivity;
16 | import pl.droidsonroids.examplerealmmvp.ui.adapter.BookListAdapter;
17 | import pl.droidsonroids.examplerealmmvp.ui.add.AddBookActivity;
18 | import pl.droidsonroids.examplerealmmvp.ui.detail.DetailActivity;
19 |
20 | public class BooksActivity extends BaseActivity implements BooksView, BookListAdapter.OnBookClickListener {
21 |
22 | @Bind(R.id.recycler_view) RecyclerView mRecyclerView;
23 | @Bind(R.id.toolbar) Toolbar mToolbar;
24 |
25 | @Inject BooksPresenter mBooksPresenter;
26 |
27 | private BookListAdapter mAdapter;
28 |
29 | @Override
30 | public void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_main);
33 | ButterKnife.bind(this);
34 |
35 | initToolbar();
36 | initList();
37 | }
38 | @Override
39 | protected Object getModule() {
40 | return new BooksModule();
41 | }
42 |
43 | private void initToolbar() {
44 | setSupportActionBar(mToolbar);
45 | }
46 |
47 | private void initList() {
48 | mAdapter = new BookListAdapter();
49 | mAdapter.setOnBookClickListener(this);
50 |
51 | mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
52 | mRecyclerView.setAdapter(mAdapter);
53 | }
54 |
55 | @Override
56 | protected void onStart() {
57 | super.onStart();
58 | mBooksPresenter.setView(this);
59 | }
60 |
61 | @Override
62 | protected void onStop() {
63 | super.onStop();
64 | mBooksPresenter.clearView();
65 | }
66 |
67 | @Override
68 | protected void closeRealm() {
69 | mBooksPresenter.closeRealm();
70 | }
71 |
72 | @Override
73 | public void showBooks(final RealmResults books) {
74 | mAdapter.setBooks(books);
75 | }
76 |
77 | @Override
78 | public void onBookClick(final int id) {
79 | mBooksPresenter.onBookClick(id);
80 | }
81 |
82 | @OnClick(R.id.fab)
83 | public void onAddNewBookClick() {
84 | mBooksPresenter.onAddNewBookClick();
85 | }
86 |
87 | @Override
88 | public void showBookDetailView(final int id) {
89 | startActivity(DetailActivity.getStartIntent(this, id));
90 | }
91 |
92 | @Override
93 | public void showAddNewBookView() {
94 | startActivity(new Intent(this, AddBookActivity.class));
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/books/BooksModule.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.books;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import pl.droidsonroids.examplerealmmvp.ApplicationModule;
6 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
7 |
8 | @Module(injects = BooksActivity.class, addsTo = ApplicationModule.class)
9 | public class BooksModule {
10 |
11 | @Provides
12 | BooksPresenter provideMyListPresenter(final RealmService realmService) {
13 | return new BooksPresenterImpl(realmService);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/books/BooksPresenter.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.books;
2 |
3 | import pl.droidsonroids.examplerealmmvp.ui.BasePresenter;
4 |
5 | public interface BooksPresenter extends BasePresenter {
6 | void onBookClick(int id);
7 | void onAddNewBookClick();
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/books/BooksPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.books;
2 |
3 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
4 |
5 | public class BooksPresenterImpl implements BooksPresenter {
6 |
7 | private final RealmService mRealmService;
8 | private BooksView mMyListView = new BooksView.EmptyMyListView();
9 |
10 | private boolean booksWereShown = false;
11 |
12 | public BooksPresenterImpl(final RealmService realmService) {
13 | mRealmService = realmService;
14 | }
15 |
16 | @Override
17 | public void setView(final BooksView view) {
18 | mMyListView = view;
19 | showBooksIfNeeded();
20 | }
21 |
22 | private void showBooksIfNeeded() {
23 | if(!booksWereShown) {
24 | mMyListView.showBooks(mRealmService.getAllBooks());
25 | booksWereShown = true;
26 | }
27 | }
28 |
29 | @Override
30 | public void clearView() {
31 | mMyListView = new BooksView.EmptyMyListView();
32 | }
33 |
34 | @Override
35 | public void closeRealm() {
36 | mRealmService.closeRealm();
37 | }
38 |
39 | @Override
40 | public void onBookClick(final int id) {
41 | mMyListView.showBookDetailView(id);
42 | }
43 |
44 | @Override
45 | public void onAddNewBookClick() {
46 | mMyListView.showAddNewBookView();
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/books/BooksView.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.books;
2 |
3 | import io.realm.RealmResults;
4 | import pl.droidsonroids.examplerealmmvp.model.Book;
5 |
6 | public interface BooksView {
7 |
8 | void showBooks(RealmResults books);
9 | void showBookDetailView(int id);
10 | void showAddNewBookView();
11 |
12 | class EmptyMyListView implements BooksView {
13 |
14 | @Override
15 | public void showBooks(final RealmResults books) {
16 |
17 | }
18 |
19 | @Override
20 | public void showBookDetailView(final int id) {
21 |
22 | }
23 |
24 | @Override
25 | public void showAddNewBookView() {
26 |
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/detail/DetailActivity.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.detail;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.widget.TextView;
7 | import butterknife.Bind;
8 | import butterknife.ButterKnife;
9 | import butterknife.OnClick;
10 | import javax.inject.Inject;
11 |
12 | import pl.droidsonroids.examplerealmmvp.R;
13 | import pl.droidsonroids.examplerealmmvp.model.Book;
14 | import pl.droidsonroids.examplerealmmvp.ui.BaseActivity;
15 | import pl.droidsonroids.examplerealmmvp.ui.author.AuthorActivity;
16 | import pl.droidsonroids.examplerealmmvp.ui.publisher.PublisherActivity;
17 |
18 | public class DetailActivity extends BaseActivity implements DetailView {
19 |
20 | private static final String EXTRA_ID = "EXTRA_ID";
21 |
22 | @Bind(R.id.text_author) TextView mTextAuthor;
23 | @Bind(R.id.text_title) TextView mTextTitle;
24 | @Bind(R.id.text_publisher) TextView mTextPublisher;
25 |
26 | @Inject DetailPresenter mMyDetailPresenter;
27 |
28 | public static Intent getStartIntent(final Context context, final int isbn) {
29 | Intent intent = new Intent(context, DetailActivity.class);
30 | intent.putExtra(EXTRA_ID, isbn);
31 | return intent;
32 | }
33 |
34 | @Override
35 | public void onCreate(Bundle savedInstanceState) {
36 | super.onCreate(savedInstanceState);
37 | setContentView(R.layout.activity_my_detail);
38 | ButterKnife.bind(this);
39 | }
40 |
41 | @Override
42 | protected Object getModule() {
43 | return new DetailModule(getIntent().getExtras().getInt(EXTRA_ID));
44 | }
45 |
46 | @Override
47 | protected void onStart() {
48 | super.onStart();
49 | mMyDetailPresenter.setView(this);
50 | }
51 |
52 | @Override
53 | protected void onStop() {
54 | super.onStop();
55 | mMyDetailPresenter.clearView();
56 | }
57 |
58 | @Override
59 | protected void closeRealm() {
60 | mMyDetailPresenter.closeRealm();
61 | }
62 |
63 | @Override
64 | public void showBookDetails(final Book book) {
65 | mTextAuthor.setText(book.getAuthorFullName());
66 | mTextTitle.setText(book.getTitle());
67 | mTextPublisher.setText(book.getPublisher().getName());
68 | }
69 |
70 | @Override
71 | public void showPublisherView(final String publisher) {
72 | startActivity(PublisherActivity.getStartIntent(this, publisher));
73 | }
74 |
75 | @Override
76 | public void showAuthorView(final String author) {
77 | startActivity(AuthorActivity.getStartIntent(this, author));
78 | }
79 |
80 | @OnClick(R.id.text_publisher)
81 | public void onPublisherClick() {
82 | mMyDetailPresenter.onPublisherClick(mTextPublisher.getText().toString());
83 | }
84 |
85 | @OnClick(R.id.text_author)
86 | public void onAuthorClick() {
87 | mMyDetailPresenter.onAuthorClick(mTextAuthor.getText().toString());
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/detail/DetailModule.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.detail;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import pl.droidsonroids.examplerealmmvp.ApplicationModule;
6 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
7 |
8 | @Module(injects = DetailActivity.class, addsTo = ApplicationModule.class)
9 | public class DetailModule {
10 |
11 | private final int mBookId;
12 |
13 | public DetailModule(final int bookId) {
14 | mBookId = bookId;
15 | }
16 |
17 | @Provides
18 | DetailPresenter provideMyDetailPresenter(final RealmService realmService) {
19 | return new DetailPresenterImpl(realmService, mBookId);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/detail/DetailPresenter.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.detail;
2 |
3 | import pl.droidsonroids.examplerealmmvp.ui.BasePresenter;
4 |
5 | public interface DetailPresenter extends BasePresenter {
6 | void onPublisherClick(String publisher);
7 | void onAuthorClick(String author);
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/detail/DetailPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.detail;
2 |
3 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
4 |
5 | public class DetailPresenterImpl implements DetailPresenter {
6 |
7 | private final RealmService mRealmService;
8 | private final int mBookId;
9 | private DetailView mMyDetailView = new DetailView.EmptyDetailView();
10 |
11 | public DetailPresenterImpl(final RealmService realmService, final int bookId) {
12 | mRealmService = realmService;
13 | mBookId = bookId;
14 | }
15 |
16 | @Override
17 | public void setView(final DetailView view) {
18 | mMyDetailView = view;
19 | mMyDetailView.showBookDetails(mRealmService.getBook(mBookId));
20 | }
21 |
22 | @Override
23 | public void clearView() {
24 | mMyDetailView = new DetailView.EmptyDetailView();
25 | }
26 |
27 | @Override
28 | public void closeRealm() {
29 | mRealmService.closeRealm();
30 | }
31 |
32 | @Override
33 | public void onPublisherClick(final String publisher) {
34 | mMyDetailView.showPublisherView(publisher);
35 | }
36 |
37 | @Override
38 | public void onAuthorClick(final String author) {
39 | mMyDetailView.showAuthorView(author);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/detail/DetailView.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.detail;
2 |
3 | import pl.droidsonroids.examplerealmmvp.model.Book;
4 |
5 | public interface DetailView {
6 |
7 | void showBookDetails(Book book);
8 | void showPublisherView(String publisher);
9 | void showAuthorView(String author);
10 |
11 | class EmptyDetailView implements DetailView {
12 |
13 | @Override
14 | public void showBookDetails(final Book book) {
15 |
16 | }
17 |
18 | @Override
19 | public void showPublisherView(final String publisher) {
20 |
21 | }
22 |
23 | @Override
24 | public void showAuthorView(final String author) {
25 |
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/publisher/PublisherActivity.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.publisher;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.widget.GridLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import butterknife.Bind;
9 | import butterknife.ButterKnife;
10 | import io.realm.RealmList;
11 | import javax.inject.Inject;
12 | import pl.droidsonroids.examplerealmmvp.R;
13 | import pl.droidsonroids.examplerealmmvp.model.Book;
14 | import pl.droidsonroids.examplerealmmvp.ui.BaseActivity;
15 | import pl.droidsonroids.examplerealmmvp.ui.adapter.BookGridAdapter;
16 |
17 | public class PublisherActivity extends BaseActivity implements PublisherView {
18 |
19 | private static final String EXTRA_PUBLISHER = "EXTRA_PUBLISHER";
20 |
21 | @Bind(R.id.recycler_view) RecyclerView mRecyclerView;
22 | @Inject PublisherPresenter mPublisherPresenter;
23 | private BookGridAdapter mAdapter;
24 |
25 | public static Intent getStartIntent(final Context context, final String publisher) {
26 | Intent intent = new Intent(context, PublisherActivity.class);
27 | intent.putExtra(EXTRA_PUBLISHER, publisher);
28 | return intent;
29 | }
30 |
31 | @Override
32 | public void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_publisher);
35 | ButterKnife.bind(this);
36 |
37 | initList();
38 | }
39 |
40 | @Override
41 | protected Object getModule() {
42 | return new PublisherModule(getIntent().getExtras().getString(EXTRA_PUBLISHER));
43 | }
44 |
45 | private void initList() {
46 | mAdapter = new BookGridAdapter();
47 | mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
48 | mRecyclerView.setAdapter(mAdapter);
49 | }
50 |
51 | @Override
52 | protected void onStart() {
53 | super.onStart();
54 | mPublisherPresenter.setView(this);
55 | }
56 |
57 | @Override
58 | protected void onStop() {
59 | super.onStop();
60 | mPublisherPresenter.clearView();
61 | }
62 |
63 | @Override
64 | protected void closeRealm() {
65 | mPublisherPresenter.closeRealm();
66 | }
67 |
68 | @Override
69 | public void showBooks(final RealmList books) {
70 | mAdapter.setBooks(books);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/publisher/PublisherModule.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.publisher;
2 |
3 | import dagger.Module;
4 | import dagger.Provides;
5 | import pl.droidsonroids.examplerealmmvp.ApplicationModule;
6 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
7 |
8 | @Module(injects = PublisherActivity.class, addsTo = ApplicationModule.class)
9 | public class PublisherModule {
10 |
11 | private final String mPublisher;
12 |
13 | public PublisherModule(final String publisher) {
14 | mPublisher = publisher;
15 | }
16 |
17 | @Provides
18 | PublisherPresenter providePublisherPresenter(final RealmService realmService) {
19 | return new PublisherPresenterImpl(realmService, mPublisher);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/publisher/PublisherPresenter.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.publisher;
2 |
3 | import pl.droidsonroids.examplerealmmvp.ui.BasePresenter;
4 |
5 | public interface PublisherPresenter extends BasePresenter {
6 | }
7 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/publisher/PublisherPresenterImpl.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.publisher;
2 |
3 | import io.realm.RealmList;
4 | import pl.droidsonroids.examplerealmmvp.model.Book;
5 | import pl.droidsonroids.examplerealmmvp.model.realm.RealmService;
6 |
7 | public class PublisherPresenterImpl implements PublisherPresenter {
8 |
9 | private final RealmService mRealmService;
10 | private final String mPublisher;
11 | private PublisherView mPublisherView = new PublisherView.EmptyPublisherView();
12 |
13 | public PublisherPresenterImpl(final RealmService realmService, final String publisher) {
14 | mRealmService = realmService;
15 | mPublisher = publisher;
16 | }
17 |
18 | @Override
19 | public void setView(final PublisherView view) {
20 | mPublisherView = view;
21 | mPublisherView.showBooks(formatBooks(mRealmService.getPublisherBooks(mPublisher)));
22 | }
23 |
24 | private RealmList formatBooks(final RealmList publisherBooks) {
25 | return publisherBooks;
26 | }
27 |
28 | @Override
29 | public void clearView() {
30 | mPublisherView = new PublisherView.EmptyPublisherView();
31 | }
32 |
33 | @Override
34 | public void closeRealm() {
35 | mRealmService.closeRealm();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/pl/droidsonroids/examplerealmmvp/ui/publisher/PublisherView.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp.ui.publisher;
2 |
3 | import io.realm.RealmList;
4 | import pl.droidsonroids.examplerealmmvp.model.Book;
5 |
6 | public interface PublisherView {
7 |
8 | void showBooks(RealmList books);
9 |
10 | class EmptyPublisherView implements PublisherView {
11 |
12 | @Override
13 | public void showBooks(final RealmList books) {
14 |
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/drawable-hdpi/ic_add_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/drawable-mdpi/ic_add_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/drawable-xhdpi/ic_add_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/drawable-xxhdpi/ic_add_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/ic_add_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/drawable-xxxhdpi/ic_add_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/layout_cover_normal.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_add_book.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
18 |
19 |
24 |
25 |
26 |
29 |
30 |
35 |
36 |
37 |
40 |
41 |
46 |
47 |
48 |
51 |
52 |
57 |
58 |
59 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_author.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
23 |
24 |
25 |
26 |
27 |
28 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_my_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
23 |
24 |
33 |
34 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_publisher.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_book.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
23 |
24 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_publisher_book.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 | 16dp
4 |
5 | 48dp
6 | 48dp
7 |
8 | 16dp
9 | 72dp
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ExampleRealmMVP
3 | Book details
4 | Add new book
5 | Title
6 | Publisher
7 | Author
8 | ISBN
9 | add
10 | Cannot add new book
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/pl/droidsonroids/examplerealmmvp/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package pl.droidsonroids.examplerealmmvp;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.0.0'
9 | classpath "io.realm:realm-gradle-plugin:0.88.3"
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DroidsOnRoids/ExampleRealmMVP-Android/5c1df26a4944b73c77206739a07bf3031f35eb14/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Apr 12 20:11:01 BRT 2016
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-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------