Search in sources :

Example 1 with TemporaryFeed

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

the class ItemPagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= 24) {
        new WebView(this);
    }
    super.onCreate(savedInstanceState);
    binding = DataBindingUtil.setContentView(this, R.layout.activity_item_pager);
    setSupportActionBar(binding.toolbarLayout.toolbar);
    final Sort order = Preferences.ORDER.getOrder(PreferenceManager.getDefaultSharedPreferences(this));
    final String sortField = Preferences.SORT_FIELD.getString(PreferenceManager.getDefaultSharedPreferences(this));
    final String title;
    if (getIntent().hasExtra("ARG_ITEMS")) {
        title = "Test";
        items = getIntent().getParcelableArrayListExtra("ARG_ITEMS");
    } else {
        TemporaryFeed.updatePagerTemporaryFeed(getRealm());
        final TemporaryFeed temporaryFeed = TemporaryFeed.getPagerTemporaryFeed(getRealm());
        items = temporaryFeed.getItems().sort(sortField, order);
        title = temporaryFeed.getName();
    }
    TypedArray typedArray = obtainStyledAttributes(new int[] { R.attr.colorPrimary, R.attr.colorAccent });
    try {
        defaultToolbarColor = typedArray.getColor(0, 0);
        // noinspection ResourceType
        defaultAccent = typedArray.getColor(1, 0);
    } finally {
        typedArray.recycle();
    }
    int position = getIntent().getIntExtra(EXTRA_CURRENT_POSITION, 0);
    // noinspection ConstantConditions
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    binding.toolbarLayout.textViewTitle.setText(title);
    binding.toolbarLayout.textViewSubtitle.setText("");
    final SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
    binding.fabOpenInBrowser.setOnClickListener(v -> {
        if (item != null && item.getUrl() != null) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.getUrl()));
            startActivity(intent);
        }
    });
    binding.fabMarkStarred.setOnClickListener(v -> setItemStarred(!item.isStarred()));
    binding.fabMarkAsRead.setOnClickListener(v -> setItemUnread(!item.isUnread()));
    binding.container.setAdapter(mSectionsPagerAdapter);
    ViewPager.OnPageChangeListener pageChangeListener = new MyOnPageChangeListener(mSectionsPagerAdapter);
    binding.container.addOnPageChangeListener(pageChangeListener);
    // The initial position is 0, so the pageChangeListener won't be called when setting the position to 0
    if (position == 0)
        pageChangeListener.onPageSelected(position);
    binding.container.setCurrentItem(position, false);
}
Also used : TypedArray(android.content.res.TypedArray) TemporaryFeed(email.schaal.ocreader.database.model.TemporaryFeed) Sort(io.realm.Sort) Intent(android.content.Intent) WebView(android.webkit.WebView) ViewPager(android.support.v4.view.ViewPager)

Example 2 with TemporaryFeed

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

the class ItemsAdapter method updateItems.

public void updateItems(boolean updateTemporaryFeed) {
    if (state.getTreeItem() == null)
        return;
    final TemporaryFeed temporaryFeed = TemporaryFeed.getListTemporaryFeed(realm);
    if (updateTemporaryFeed || temporaryFeed.getTreeItemId() != state.getTreeItem().getId()) {
        realm.executeTransaction(realm -> {
            List<Item> tempItems = state.getTreeItem().getItems(realm, isOnlyUnread());
            temporaryFeed.setTreeItemId(state.getTreeItem().getId());
            temporaryFeed.setName(state.getTreeItem().getName());
            temporaryFeed.getItems().clear();
            if (tempItems != null) {
                temporaryFeed.getItems().addAll(tempItems);
            }
        });
    }
    items = temporaryFeed.getItems().sort(Preferences.SORT_FIELD.getString(preferences), Preferences.ORDER.getOrder(preferences));
    notifyDataSetChanged();
}
Also used : Item(email.schaal.ocreader.database.model.Item) TemporaryFeed(email.schaal.ocreader.database.model.TemporaryFeed)

Aggregations

TemporaryFeed (email.schaal.ocreader.database.model.TemporaryFeed)2 Intent (android.content.Intent)1 TypedArray (android.content.res.TypedArray)1 ViewPager (android.support.v4.view.ViewPager)1 WebView (android.webkit.WebView)1 Item (email.schaal.ocreader.database.model.Item)1 Sort (io.realm.Sort)1