use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.
the class ListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = DataBindingUtil.setContentView(this, R.layout.activity_list);
setSupportActionBar(binding.toolbarLayout.toolbar);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
binding.swipeRefreshLayout.setColorSchemeResources(R.color.primary);
binding.swipeRefreshLayout.setOnRefreshListener(this);
profileDrawerItem = new ProfileDrawerItem().withName(preferences.getString(Preferences.USERNAME.getKey(), getString(R.string.app_name))).withEmail(Preferences.URL.getString(preferences));
updateUserProfile();
IProfile profileSettingsItem = new ProfileSettingDrawerItem().withName(getString(R.string.account_settings)).withIconTinted(true).withIcon(R.drawable.ic_settings).withTag((Runnable) () -> {
Intent loginIntent = new Intent(ListActivity.this, LoginActivity.class);
startActivityForResult(loginIntent, LoginActivity.REQUEST_CODE);
});
accountHeader = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header_background).addProfiles(profileDrawerItem, profileSettingsItem).withCurrentProfileHiddenInList(true).withProfileImagesClickable(false).withSavedInstance(savedInstanceState).withOnAccountHeaderListener((view, profile, current) -> {
if (profile instanceof Tagable) {
Tagable tagable = (Tagable) profile;
if (tagable.getTag() instanceof Runnable) {
((Runnable) tagable.getTag()).run();
return false;
}
}
return true;
}).build();
refreshDrawerItem = new PrimaryDrawerItem().withName(getString(R.string.action_sync)).withSelectable(false).withIconTintingEnabled(true).withIcon(R.drawable.ic_refresh).withIdentifier(REFRESH_DRAWER_ITEM_ID).withTag((Runnable) () -> SyncService.startSync(ListActivity.this));
IDrawerItem settingsDrawerItem = new PrimaryDrawerItem().withName(R.string.settings).withIcon(R.drawable.ic_settings).withIconTintingEnabled(true).withSelectable(false).withTag((Runnable) () -> {
startDrawer.closeDrawer();
Intent settingsIntent = new Intent(ListActivity.this, SettingsActivity.class);
startActivity(settingsIntent);
});
DrawerBuilder startDrawerBuilder = new DrawerBuilder().withActivity(this).withAccountHeader(accountHeader).addStickyDrawerItems(settingsDrawerItem, refreshDrawerItem).withOnDrawerListener(new Drawer.OnDrawerListener() {
@Override
public void onDrawerOpened(View drawerView) {
drawerManager.getStartAdapter().updateUnreadCount(getRealm(), isShowOnlyUnread());
}
@Override
public void onDrawerClosed(View drawerView) {
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
}).withOnDrawerItemClickListener((view, position, drawerItem) -> {
if (drawerItem.getTag() instanceof TreeItem) {
TreeItem item = (TreeItem) drawerItem.getTag();
onStartDrawerItemClicked(item);
return false;
} else if (drawerItem.getTag() instanceof Runnable) {
((Runnable) drawerItem.getTag()).run();
}
return true;
}).withSavedInstance(savedInstanceState);
DrawerBuilder endDrawerBuilder = new DrawerBuilder().withActivity(this).withDrawerGravity(Gravity.END).withSavedInstance(savedInstanceState).withShowDrawerOnFirstLaunch(true).withOnDrawerListener(new Drawer.OnDrawerListener() {
@Override
public void onDrawerOpened(View drawerView) {
drawerManager.getEndAdapter().updateUnreadCount(getRealm(), isShowOnlyUnread());
}
@Override
public void onDrawerClosed(View drawerView) {
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
}).withOnDrawerItemClickListener((view, position, drawerItem) -> {
if (drawerItem.getTag() instanceof Feed) {
Feed feed = (Feed) drawerItem.getTag();
onEndDrawerItemClicked(feed);
return false;
}
return true;
});
startDrawerBuilder.withToolbar(binding.toolbarLayout.toolbar);
startDrawer = startDrawerBuilder.build();
drawerManager = new DrawerManager(this, startDrawer, endDrawerBuilder.append(startDrawer), unreadSwitchListener);
layoutManager = new LinearLayoutManager(this);
adapter = new ErrorAdapter(this, getRealm(), drawerManager.getState(), this, this);
binding.fabMarkAllAsRead.setOnClickListener(new View.OnClickListener() {
private void onCompletion(View view) {
adapter.updateItems(false);
view.setEnabled(true);
binding.fabMarkAllAsRead.toggleSync();
}
@Override
public void onClick(final View view) {
if (binding.fabMarkAllAsRead.isSync()) {
SyncService.startSync(ListActivity.this);
binding.fabMarkAllAsRead.toggleSync();
} else {
Queries.markTemporaryFeedAsRead(getRealm(), () -> onCompletion(view), error -> {
Log.e(TAG, "Failed to mark temporary feed as read", error);
onCompletion(view);
});
}
}
});
binding.fabMarkAllAsRead.setOnLongClickListener(v -> {
Toast.makeText(ListActivity.this, R.string.mark_all_as_read, Toast.LENGTH_SHORT).show();
return true;
});
binding.itemsRecyclerview.setAdapter(adapter);
binding.itemsRecyclerview.setLayoutManager(layoutManager);
if (savedInstanceState == null && getIntent().hasExtra(SyncService.EXTRA_ID)) {
drawerManager.getState().restore(getRealm(), getIntent().getIntExtra(SyncService.EXTRA_ID, -10), null, false);
} else {
drawerManager.getState().restoreInstanceState(getRealm(), getPreferences(MODE_PRIVATE));
}
binding.itemsRecyclerview.addItemDecoration(new DividerItemDecoration(this, R.dimen.divider_inset));
adapter.updateItems(false);
if (savedInstanceState != null) {
layoutManager.onRestoreInstanceState(savedInstanceState.getParcelable(LAYOUT_MANAGER_STATE));
adapter.onRestoreInstanceState(savedInstanceState);
if (adapter.getSelectedItemsCount() > 0) {
actionMode = startActionMode(this);
}
}
drawerManager.reloadAdapters(getRealm(), isShowOnlyUnread());
// noinspection ConstantConditions
getSupportActionBar().setTitle(drawerManager.getState().getTreeItem().getName());
}
use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.
the class APIv2 method createFeed.
@Override
public void createFeed(final Realm realm, String url, long folderId, APICallback<Void, Throwable> apiCallback) {
final Feed feed = new Feed();
feed.setUrl(url);
feed.setFolderId(folderId);
api.createFeed(feed).enqueue(new BaseRetrofitCallback<Feeds>(apiCallback) {
@Override
protected void onResponseReal(final Response<Feeds> response) {
final Feeds feeds = response.body();
if (feeds != null) {
// Set unreadCount to 0, items have not been fetched yet for this feed
Feed feed = feeds.getFeeds().get(0);
feed.setUnreadCount(0);
Queries.insert(realm, feed);
}
}
});
}
use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.
the class TestGenerator method getTestFeed.
static Feed getTestFeed(long id) {
Feed feed = new Feed(id);
feed.setFolderId(0L);
feed.setName(FEED_TITLE);
return feed;
}
use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.
the class FeedsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof FeedViewHolder) {
Feed feed = getItem(position);
((FeedViewHolder) holder).bindFeed(feed);
}
}
use of email.schaal.ocreader.database.model.Feed in project ocreader by schaal.
the class ItemViewHolder method bindItem.
public void bindItem(final Item item, final int position, boolean selected) {
binding.textViewTitle.setText(item.getTitle());
Feed feed = item.getFeed();
if (feed != null) {
binding.textViewFeedTitle.setText(feed.getName());
} else {
Log.w(TAG, "Feed == null");
binding.textViewFeedTitle.setText("");
}
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(binding.getRoot().getContext());
final Date date;
if (Preferences.SORT_FIELD.getString(preferences).equals(Item.UPDATED_AT))
date = item.getUpdatedAt();
else
date = item.getPubDate();
binding.textViewTime.setText(StringUtils.getTimeSpanString(itemView.getContext(), date));
binding.textViewFeedTitle.setTextColor(defaultFeedTextColor);
new FaviconLoader.Builder(binding.imageviewFavicon).build().load(binding.imageviewFavicon.getContext(), feed, this);
itemView.setOnClickListener(view -> clickListener.onItemClick(item, position));
itemView.setOnLongClickListener(v -> {
clickListener.onItemLongClick(item, position);
return true;
});
if (item.getEnclosureLink() != null) {
binding.play.setVisibility(View.VISIBLE);
binding.play.setOnClickListener(view -> item.play(itemView.getContext()));
} else {
binding.play.setVisibility(View.GONE);
binding.play.setOnClickListener(null);
}
setUnreadState(item.isUnread());
setStarredState(item.isStarred());
setSelected(selected);
}
Aggregations