Search in sources :

Example 1 with PlacementBlogPost

use of app.insti.api.model.PlacementBlogPost in project IITB-App by wncc.

the class NotificationsAdapter method onClick.

@Override
public void onClick(Notification notification, FragmentActivity fragmentActivity) {
    /* Mark notification read */
    RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
    String sessId = Utils.getSessionIDHeader();
    retrofitInterface.markNotificationRead(sessId, notification.getNotificationId().toString()).enqueue(new EmptyCallback<Void>());
    ShortcutBadger.applyCount(fragmentActivity.getApplicationContext(), NotificationId.decrementAndGetCurrentCount());
    /* Close the bottom sheet */
    notificationsFragment.dismiss();
    Gson gson = Utils.gson;
    /* Open event */
    if (notification.isEvent()) {
        Event event = gson.fromJson(gson.toJson(notification.getNotificationActor()), Event.class);
        Utils.openEventFragment(event, fragmentActivity);
    } else if (notification.isNews()) {
        NewsFragment newsFragment = new NewsFragment();
        NewsArticle newsArticle = gson.fromJson(gson.toJson(notification.getNotificationActor()), NewsArticle.class);
        newsFragment.withId(newsArticle.getId());
        Utils.updateFragment(newsFragment, fragmentActivity);
    } else if (notification.isBlogPost()) {
        PlacementBlogPost post = gson.fromJson(gson.toJson(notification.getNotificationActor()), PlacementBlogPost.class);
        Fragment fragment;
        if (post.getLink().contains("training")) {
            fragment = (new TrainingBlogFragment()).withId(post.getId());
        } else {
            fragment = (new PlacementBlogFragment()).withId(post.getId());
        }
        Utils.updateFragment(fragment, fragmentActivity);
    }
}
Also used : NewsArticle(app.insti.api.model.NewsArticle) PlacementBlogPost(app.insti.api.model.PlacementBlogPost) PlacementBlogFragment(app.insti.fragment.PlacementBlogFragment) Gson(com.google.gson.Gson) Event(app.insti.api.model.Event) NewsFragment(app.insti.fragment.NewsFragment) NotificationsFragment(app.insti.fragment.NotificationsFragment) NewsFragment(app.insti.fragment.NewsFragment) TrainingBlogFragment(app.insti.fragment.TrainingBlogFragment) Fragment(androidx.fragment.app.Fragment) PlacementBlogFragment(app.insti.fragment.PlacementBlogFragment) TrainingBlogFragment(app.insti.fragment.TrainingBlogFragment) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 2 with PlacementBlogPost

use of app.insti.api.model.PlacementBlogPost in project IITB-App by wncc.

the class PlacementBlogAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder recyclerHolder, int position) {
    if (recyclerHolder instanceof ViewHolder) {
        ViewHolder holder = (ViewHolder) recyclerHolder;
        PlacementBlogPost post = getPosts().get(position);
        Utils.getMarkwon(false).setMarkdown(holder.postTitle, post.getTitle());
        Date publishedDate = post.getPublished();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(publishedDate);
        DateFormat displayFormat;
        if (calendar.get(Calendar.YEAR) == Calendar.getInstance().get(Calendar.YEAR)) {
            displayFormat = new SimpleDateFormat("EEE, MMM d, HH:mm", Locale.US);
        } else {
            displayFormat = new SimpleDateFormat("EEE, MMM d, ''yy, HH:mm", Locale.US);
        }
        holder.postPublished.setText(displayFormat.format(publishedDate));
        Utils.getMarkwon(false).setMarkdown(holder.postContent, post.getContent());
    } else {
        ((ProgressViewHolder) recyclerHolder).progressBar.setIndeterminate(true);
    }
}
Also used : PlacementBlogPost(app.insti.api.model.PlacementBlogPost) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

PlacementBlogPost (app.insti.api.model.PlacementBlogPost)2 Fragment (androidx.fragment.app.Fragment)1 RetrofitInterface (app.insti.api.RetrofitInterface)1 Event (app.insti.api.model.Event)1 NewsArticle (app.insti.api.model.NewsArticle)1 NewsFragment (app.insti.fragment.NewsFragment)1 NotificationsFragment (app.insti.fragment.NotificationsFragment)1 PlacementBlogFragment (app.insti.fragment.PlacementBlogFragment)1 TrainingBlogFragment (app.insti.fragment.TrainingBlogFragment)1 Gson (com.google.gson.Gson)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1