Search in sources :

Example 6 with Feed

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

the class JsonTest method TestJsonWithUnexpectedNull.

@Test
public void TestJsonWithUnexpectedNull() throws IOException {
    Moshi moshi = new Moshi.Builder().add(Feed.class, new FeedTypeAdapter()).build();
    String feedJson = "{\"id\":28,\"url\":\"http://rss.slashdot.org/Slashdot/slashdot\",\"title\":\"Slashdot\",\"faviconLink\":null,\"added\":1435334890,\"folderId\":0,\"unreadCount\":1093,\"ordering\":null,\"link\":\"http://slashdot.org/\",\"pinned\":false}";
    Feed feed = moshi.adapter(Feed.class).fromJson(feedJson);
    assertNull(feed.getFaviconLink());
}
Also used : Moshi(com.squareup.moshi.Moshi) FeedTypeAdapter(email.schaal.ocreader.api.json.FeedTypeAdapter) Feed(email.schaal.ocreader.database.model.Feed) Test(org.junit.Test)

Example 7 with Feed

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

the class ManageFeedsActivity method changeFeed.

@Override
public void changeFeed(final long feedId, final long folderId) {
    final Feed feed = Feed.get(getRealm(), feedId);
    final ProgressDialog progressDialog = showProgress(this, getString(R.string.moving_feed));
    API.get(this, new API.InstanceReadyCallback() {

        @Override
        public void onInstanceReady(API api) {
            api.moveFeed(getRealm(), feed, folderId, new API.APICallback<Void, Throwable>() {

                @Override
                public void onSuccess(Void v) {
                    progressDialog.dismiss();
                    setResult(RESULT_OK);
                }

                @Override
                public void onFailure(Throwable throwable) {
                    progressDialog.cancel();
                    showErrorMessage(getString(R.string.feed_move_failed), throwable.getLocalizedMessage());
                }
            });
        }

        @Override
        public void onLoginFailure(Throwable e) {
            progressDialog.cancel();
        }
    });
}
Also used : API(email.schaal.ocreader.api.API) ProgressDialog(android.app.ProgressDialog) Feed(email.schaal.ocreader.database.model.Feed)

Example 8 with Feed

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

the class ManageFeedsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActivityManageFeedsBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_manage_feeds);
    setSupportActionBar(binding.toolbarLayout.toolbar);
    // noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    folderSpinnerAdapter = new FolderSpinnerAdapter(this, getRealm().where(Folder.class).sort(Folder.NAME).findAll());
    FeedsAdapter adapter = new FeedsAdapter(getRealm(), this);
    binding.feedsRecyclerview.setAdapter(adapter);
    binding.feedsRecyclerview.setLayoutManager(new LinearLayoutManager(this));
    binding.feedsRecyclerview.addItemDecoration(new DividerItemDecoration(this, R.dimen.divider_inset));
    binding.fabAddFeed.setOnClickListener(view -> AddNewFeedDialogFragment.show(ManageFeedsActivity.this, null, false));
    if (Intent.ACTION_SEND.equals(getIntent().getAction())) {
        Feed feed = new Feed(-1);
        feed.setUrl(getIntent().getStringExtra(Intent.EXTRA_TEXT));
        AddNewFeedDialogFragment.show(this, feed, true);
    }
}
Also used : FeedsAdapter(email.schaal.ocreader.view.FeedsAdapter) ActivityManageFeedsBinding(email.schaal.ocreader.databinding.ActivityManageFeedsBinding) FolderSpinnerAdapter(email.schaal.ocreader.view.FolderSpinnerAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(email.schaal.ocreader.view.DividerItemDecoration) Feed(email.schaal.ocreader.database.model.Feed)

Example 9 with Feed

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

the class APIv2 method moveFeed.

@Override
public void moveFeed(final Realm realm, final Feed feed, final long folderId, APICallback<Void, Throwable> apiCallback) {
    final Feed changedFeed = new Feed();
    changedFeed.setUrl(feed.getUrl());
    changedFeed.setFolderId(feed.getFolderId());
    api.changeFeed(feed.getId(), changedFeed).enqueue(new BaseRetrofitCallback<Map<String, Feed>>(apiCallback) {

        @Override
        protected void onResponseReal(Response<Map<String, Feed>> response) {
            final Map<String, Feed> feedMap = response.body();
            if (feedMap != null)
                Queries.insert(realm, feedMap.get("feed"));
        }
    });
}
Also used : Map(java.util.Map) Feed(email.schaal.ocreader.database.model.Feed)

Example 10 with Feed

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

the class DatabaseTest method testFeedInsert.

@Test
public void testFeedInsert() {
    Realm realm = null;
    try {
        Feed feed = getTestFeed();
        realm = Realm.getDefaultInstance();
        Queries.insert(realm, feed);
        feed = Feed.get(realm, 1);
        assertNotNull(feed);
        assertEquals(feed.getName(), FEED_TITLE);
    } finally {
        assertNotNull(realm);
        realm.close();
    }
}
Also used : Realm(io.realm.Realm) Feed(email.schaal.ocreader.database.model.Feed) TestGenerator.getTestFeed(email.schaal.ocreader.TestGenerator.getTestFeed) 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