Search in sources :

Example 11 with Feed

use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.

the class DatabaseTest method testItemInsert.

@Test
public void testItemInsert() {
    Realm realm = null;
    try {
        Feed feed = getTestFeed();
        Item item = getTestItem();
        realm = Realm.getDefaultInstance();
        Queries.insert(realm, feed);
        Queries.insert(realm, item);
        item = realm.where(Item.class).findFirst();
        assertEquals(item.getId(), 1);
        assertEquals(item.getTitle(), ITEM_TITLE);
        assertEquals(item.getBody(), BODY);
        assertEquals(item.getAuthor(), AUTHOR);
        assertNull(item.getEnclosureLink());
    } finally {
        assertNotNull(realm);
        realm.close();
    }
}
Also used : TestGenerator.getTestItem(email.schaal.ocreader.TestGenerator.getTestItem) Item(email.schaal.ocreader.database.model.Item) Realm(io.realm.Realm) Feed(email.schaal.ocreader.database.model.Feed) TestGenerator.getTestFeed(email.schaal.ocreader.TestGenerator.getTestFeed) Test(org.junit.Test)

Example 12 with Feed

use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.

the class FeedTypeAdapter method fromJson.

@Override
public Feed fromJson(@NonNull JsonReader in) throws IOException {
    if (in.peek() == JsonReader.Token.NULL) {
        in.nextNull();
        return null;
    }
    final NullableJsonReader reader = new NullableJsonReader(in);
    final Feed feed = new Feed();
    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        switch(name) {
            case "id":
                feed.setId(in.nextLong());
                break;
            case "url":
                feed.setUrl(reader.nextString());
                break;
            case "link":
                feed.setLink(reader.nextString());
                break;
            case "faviconLink":
                String faviconLink = reader.nextString();
                if (faviconLink != null && TextUtils.getTrimmedLength(faviconLink) == 0)
                    faviconLink = null;
                feed.setFaviconLink(faviconLink);
                break;
            // title in API v1-2, name in API v2
            case "title":
            case "name":
                feed.setName(StringUtils.cleanString(in.nextString()));
                break;
            case "added":
                in.skipValue();
                break;
            case "folderId":
                feed.setFolderId(in.nextLong());
                break;
            case "unreadCount":
                // skip unreadCount, calculated later in SyncService
                in.skipValue();
                break;
            case "ordering":
                // createFeed returns a feed with ordering set to NULL
                feed.setOrdering(reader.nextInt(0));
                break;
            case "pinned":
                // createFeed returns a feed with pinned set to NULL
                feed.setPinned(reader.nextBoolean(false));
                break;
            case "updateErrorCount":
                feed.setUpdateErrorCount(reader.nextInt(0));
                break;
            case "lastUpdateError":
                feed.setLastUpdateError(reader.nextString());
                break;
            case "error":
                parseError(reader, feed);
                break;
            default:
                Log.w(TAG, "Unknown value in feed json: " + name);
                in.skipValue();
                break;
        }
    }
    in.endObject();
    return feed;
}
Also used : Feed(email.schaal.ocreader.database.model.Feed)

Example 13 with Feed

use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.

the class FaviconLoaderTest method testGetDrawable.

@Test
public void testGetDrawable() throws Exception {
    Feed feed = new Feed();
    feed.setName("Test");
    feed.setUrl("http://example.com");
    feed.setFaviconLink(null);
    assertTrue(FaviconLoader.getDrawable(RuntimeEnvironment.application, feed) instanceof TextDrawable);
    assertEquals(AppCompatResources.getDrawable(RuntimeEnvironment.application, R.drawable.ic_feed_icon), FaviconLoader.getDrawable(RuntimeEnvironment.application, null));
// TODO: 01.08.16 Test feed with favicon
}
Also used : TextDrawable(email.schaal.ocreader.util.TextDrawable) Feed(email.schaal.ocreader.database.model.Feed) Test(org.junit.Test)

Aggregations

Feed (email.schaal.ocreader.database.model.Feed)13 Test (org.junit.Test)3 SharedPreferences (android.content.SharedPreferences)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 TestGenerator.getTestFeed (email.schaal.ocreader.TestGenerator.getTestFeed)2 Realm (io.realm.Realm)2 Activity (android.app.Activity)1 ProgressDialog (android.app.ProgressDialog)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 DataBindingUtil (android.databinding.DataBindingUtil)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 Bundle (android.os.Bundle)1 PreferenceManager (android.preference.PreferenceManager)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 Snackbar (android.support.design.widget.Snackbar)1 ContextCompat (android.support.v4.content.ContextCompat)1