Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shmakova Anastasia - @shmakova #4

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ dependencies {
apt libraries.butterKnifeCompiler

compile libraries.timber
compile libraries.glide

compile libraries.rxJava
compile libraries.rxAndroid

compile libraries.icepick
provided libraries.icepickProcessor

compile libraries.fragmentargs
apt libraries.fragmentargsProcessor

// Developer tools (Developer Settings)
compile libraries.stetho
Expand Down
76 changes: 76 additions & 0 deletions app/src/androidTest/java/ru/yandex/yamblz/ApplicationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ru.yandex.yamblz;

import android.support.test.espresso.matcher.BoundedMatcher;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import ru.yandex.yamblz.data.models.Artist;
import ru.yandex.yamblz.ui.activities.MainActivity;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.CoreMatchers.allOf;

@RunWith(AndroidJUnit4.class)
@LargeTest
public class ApplicationTest {
private static final String ARTIST_NAME = "Сплин";
private static final String ARTIST_GENRES = "rusrock";

@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
MainActivity.class);

@Test
public void ApplicationTest() {
// find Artist in Artists list with ARTIST_NAME name and ARTIST_GENRES genres and tap on it
onData(allOf(withArtistName(ARTIST_NAME), withGenres(ARTIST_GENRES))).perform(click());

// check visibility all items in the opened activity
onView(withId(R.id.biography)).check(matches(isDisplayed()));
onView(withId(R.id.genres)).check(matches(withText(ARTIST_GENRES)));
onView(withId(R.id.info)).check(matches(isDisplayed()));
onView(withId(R.id.description)).check(matches(isDisplayed()));
onView(withId(R.id.cover_big)).check(matches(isDisplayed()));
}

public static Matcher<Object> withArtistName(final String artistName) {
return new BoundedMatcher<Object, Artist>(Artist.class) {
@Override
protected boolean matchesSafely(Artist artist) {
return artistName.equals(artist.getName());
}

@Override
public void describeTo(Description description) {
description.appendText("with id: " + artistName);
}
};
}

public static Matcher<Object> withGenres(final String genres) {
return new BoundedMatcher<Object, Artist>(Artist.class) {
@Override
protected boolean matchesSafely(Artist artist) {
return genres.equals(artist.getGenres());
}

@Override
public void describeTo(Description description) {
description.appendText("with id: " + genres);
}
};
}
}
20 changes: 10 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.yandex.yamblz">
package="ru.yandex.yamblz">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:name="ru.yandex.yamblz.App"
android:allowBackup="false"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme.NoActionBar">
<activity
android:name="ru.yandex.yamblz.ui.activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
android:label="@string/main_activity_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
</manifest>
5 changes: 3 additions & 2 deletions app/src/main/java/ru/yandex/yamblz/ApplicationComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public interface ApplicationComponent {

DevMetricsProxy devMetricsProxy();

@NonNull @Named(ApplicationModule.MAIN_THREAD_HANDLER)
@NonNull
@Named(ApplicationModule.MAIN_THREAD_HANDLER)
Handler mainThreadHandler();

void inject(@NonNull MainActivity mainActivity);
}
}
42 changes: 42 additions & 0 deletions app/src/main/java/ru/yandex/yamblz/data/IterableCursor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.yandex.yamblz.data;

/**
* Created by shmakova on 07.08.16.
*/

import android.database.Cursor;

import java.util.Iterator;

public class IterableCursor implements Iterable<Cursor> {
private Cursor cursor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Рекомендую посмотреть на StorIO. https://github.com/pushtorefresh/storio

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Впилила StorIO


public IterableCursor(Cursor cursor) {
this.cursor = cursor;
if (cursor != null) {
this.cursor.moveToPosition(-1);
}
}

@Override
public Iterator<Cursor> iterator() {
return new Iterator<Cursor>() {
@Override
public boolean hasNext() {
if (cursor != null && cursor.isClosed() && !cursor.moveToNext()) {
cursor.close();
}
return cursor != null && !cursor.isClosed() && cursor.moveToNext();
}

@Override
public Cursor next() {
return cursor;
}

@Override
public void remove() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new UnsupportedOperationException();

}
};
}
}
187 changes: 187 additions & 0 deletions app/src/main/java/ru/yandex/yamblz/data/models/Artist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package ru.yandex.yamblz.data.models;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже посоветую посмотреть на AutoValue + AutoParcel + Moshi, как будет время.


import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* Created by shmakova on 12.04.16.
*/
public class Artist implements Parcelable {
private int id;
private String name;
private List<String> genres;
private Cover cover;
private int tracks;
private int albums;
private String description;
private String link;

private Artist(int id, String name, List<String> genres, Cover cover, int tracks, int albums, String description, String link) {
this.id = id;
this.name = name;
this.genres = genres;
this.cover = cover;
this.tracks = tracks;
this.albums = albums;
this.description = description;
this.link = link;
}

public String getDescription() {
return description;
}

public String getLink() {
return link;
}

public int getTracks() {
return tracks;
}

public int getAlbums() {
return albums;
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public Cover getCover() {
return cover;
}

public String getGenres() {
return TextUtils.join(", ", genres);
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.id);
dest.writeString(this.name);
dest.writeStringList(this.genres);
dest.writeParcelable(this.cover, flags);
dest.writeInt(this.tracks);
dest.writeInt(this.albums);
dest.writeString(this.description);
dest.writeString(this.link);
}

private Artist(Parcel in) {
this.id = in.readInt();
this.name = in.readString();
this.genres = in.createStringArrayList();
this.cover = in.readParcelable(Cover.class.getClassLoader());
this.tracks = in.readInt();
this.albums = in.readInt();
this.description = in.readString();
this.link = in.readString();
}

public static final Parcelable.Creator<Artist> CREATOR = new Parcelable.Creator<Artist>() {
@Override
public Artist createFromParcel(Parcel source) {
return new Artist(source);
}

@Override
public Artist[] newArray(int size) {
return new Artist[size];
}
};

@Override
public String toString() {
return "Artist: " + name;
}

public static class Builder {
private int id;
private String name;
private List<String> genres;
private Cover cover;
private int tracks;
private int albums;
private String description;
private String link;

public Builder setId(int id) {
this.id = id;
return this;
}

public Builder setName(String name) {
this.name = name;
return this;
}

public Builder setGenres(List<String> genres) {
this.genres = genres;
return this;
}

public Builder setCover(Cover cover) {
this.cover = cover;
return this;
}

public Builder setTracks(int tracks) {
this.tracks = tracks;
return this;
}

public Builder setAlbums(int albums) {
this.albums = albums;
return this;
}

public Builder setDescription(String description) {
this.description = description;
return this;
}

public Builder setLink(String link) {
this.link = link;
return this;
}

public Artist build() {
return new Artist(id, name, genres, cover, tracks, albums, description, link);
}
}

public static Artist getArtistFromCursor(Cursor cursor) {
String genresString = cursor.getString(8);
List<String> genres = new ArrayList<>(Collections.singletonList(genresString));

Cover cover = new Cover(
cursor.getString(6),
cursor.getString(7)
);

return new Artist.Builder()
.setName(cursor.getString(1))
.setTracks(cursor.getInt(2))
.setAlbums(cursor.getInt(3))
.setGenres(genres)
.setCover(cover)
.setDescription(cursor.getString(4))
.setLink(cursor.getString(5))
.build();
}
}
Loading