Search in sources :

Example 11 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class FluxCMigrationTest method testDraftMigration.

public void testDraftMigration() throws DuplicateSiteException {
    TestUtils.loadDBFromDump(mRenamingTargetAppContext, mTestContext, "FluxC-migration.sql");
    // Migrate sites first so that SiteStore is populated
    List<SiteModel> sites = WPLegacyMigrationUtils.getSelfHostedSitesFromDeprecatedDB(mRenamingTargetAppContext);
    for (SiteModel site : sites) {
        SiteSqlUtils.insertOrUpdateSite(site);
    }
    AppLog.d(AppLog.T.DB, "Added " + mSiteStore.getSitesCount() + " sites to SiteStore");
    List<PostModel> posts = WPLegacyMigrationUtils.getDraftsFromDeprecatedDB(mRenamingTargetAppContext, mSiteStore);
    AppLog.d(AppLog.T.DB, "Extracted " + posts.size() + " drafts from legacy DB");
    assertEquals(3, posts.size());
    assertEquals("", posts.get(0).getTitle());
    assertEquals("This is a title", posts.get(1).getTitle());
    assertEquals("This is a title also", posts.get(2).getTitle());
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) PostModel(org.wordpress.android.fluxc.model.PostModel)

Example 12 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class CommentDetailFragment method showComment.

/*
     * display the current comment
     */
private void showComment() {
    if (!isAdded() || getView() == null)
        return;
    // these two views contain all the other views except the progress bar
    final ScrollView scrollView = (ScrollView) getView().findViewById(R.id.scroll_view);
    final View layoutBottom = getView().findViewById(R.id.layout_bottom);
    // hide container views when comment is null (will happen when opened from a notification)
    if (mComment == null) {
        scrollView.setVisibility(View.GONE);
        layoutBottom.setVisibility(View.GONE);
        if (mNote != null) {
            SiteModel site = mSiteStore.getSiteBySiteId(mNote.getSiteId());
            if (site == null) {
                ToastUtils.showToast(getActivity(), R.string.error_load_comment);
                return;
            }
            // Check if the comment is already in our store
            CommentModel comment = mCommentStore.getCommentBySiteAndRemoteId(site, mNote.getCommentId());
            if (comment != null) {
                // It exists, then show it as a "Notification"
                showCommentAsNotification(mNote, site, comment);
            } else {
                // It's not in our store yet, request it.
                RemoteCommentPayload payload = new RemoteCommentPayload(site, mNote.getCommentId());
                mDispatcher.dispatch(CommentActionBuilder.newFetchCommentAction(payload));
                setProgressVisible(true);
                // Show a "temporary" comment built from the note data, the view will be refreshed once the
                // comment has been fetched.
                showCommentAsNotification(mNote, site, null);
            }
        }
        return;
    }
    scrollView.setVisibility(View.VISIBLE);
    layoutBottom.setVisibility(View.VISIBLE);
    // Add action buttons footer
    if (mNote == null && mLayoutButtons.getParent() == null) {
        mCommentContentLayout.addView(mLayoutButtons);
    }
    final WPNetworkImageView imgAvatar = (WPNetworkImageView) getView().findViewById(R.id.image_avatar);
    final TextView txtName = (TextView) getView().findViewById(R.id.text_name);
    final TextView txtDate = (TextView) getView().findViewById(R.id.text_date);
    txtName.setText(mComment.getAuthorName() == null ? getString(R.string.anonymous) : HtmlUtils.fastUnescapeHtml(mComment.getAuthorName()));
    txtDate.setText(DateTimeUtils.javaDateToTimeSpan(DateTimeUtils.dateFromIso8601(mComment.getDatePublished()), WordPress.getContext()));
    int maxImageSz = getResources().getDimensionPixelSize(R.dimen.reader_comment_max_image_size);
    CommentUtils.displayHtmlComment(mTxtContent, mComment.getContent(), maxImageSz, mImageLoader);
    int avatarSz = getResources().getDimensionPixelSize(R.dimen.avatar_sz_large);
    if (mComment.getAuthorProfileImageUrl() != null) {
        imgAvatar.setImageUrl(GravatarUtils.fixGravatarUrl(mComment.getAuthorProfileImageUrl(), avatarSz), WPNetworkImageView.ImageType.AVATAR);
    } else if (mComment.getAuthorEmail() != null) {
        String avatarUrl = GravatarUtils.gravatarFromEmail(mComment.getAuthorEmail(), avatarSz);
        imgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
    } else {
        imgAvatar.setImageUrl(null, WPNetworkImageView.ImageType.AVATAR);
    }
    updateStatusViews();
    // navigate to author's blog when avatar or name clicked
    if (mComment.getAuthorUrl() != null) {
        View.OnClickListener authorListener = new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ReaderActivityLauncher.openUrl(getActivity(), mComment.getAuthorUrl());
            }
        };
        imgAvatar.setOnClickListener(authorListener);
        txtName.setOnClickListener(authorListener);
        txtName.setTextColor(ContextCompat.getColor(getActivity(), R.color.reader_hyperlink));
    } else {
        txtName.setTextColor(ContextCompat.getColor(getActivity(), R.color.grey_darken_30));
    }
    showPostTitle(mSite, mComment.getRemotePostId());
    // make sure reply box is showing
    if (mLayoutReply.getVisibility() != View.VISIBLE && canReply()) {
        AniUtils.animateBottomBar(mLayoutReply, true);
        if (mEditReply != null && mShouldFocusReplyField) {
            mEditReply.performClick();
            disableShouldFocusReplyField();
        }
    }
    getFragmentManager().invalidateOptionsMenu();
}
Also used : ScrollView(android.widget.ScrollView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) SiteModel(org.wordpress.android.fluxc.model.SiteModel) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) ScrollView(android.widget.ScrollView) CommentModel(org.wordpress.android.fluxc.model.CommentModel) RemoteCommentPayload(org.wordpress.android.fluxc.store.CommentStore.RemoteCommentPayload)

Example 13 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class CommentDetailFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getActivity().getApplication()).component().inject(this);
    switch(getArguments().getInt(KEY_MODE)) {
        case FROM_BLOG_COMMENT:
            setComment((CommentModel) getArguments().getSerializable(KEY_COMMENT), (SiteModel) getArguments().getSerializable(WordPress.SITE));
            break;
        case FROM_NOTE:
            setNote(getArguments().getString(KEY_NOTE_ID));
            setReplyText(getArguments().getString(KEY_REPLY_TEXT));
            setIdForFragmentContainer(getArguments().getInt(KEY_FRAGMENT_CONTAINER_ID));
            break;
    }
    if (savedInstanceState != null) {
        mIdForFragmentContainer = savedInstanceState.getInt(KEY_FRAGMENT_CONTAINER_ID);
        if (savedInstanceState.getString(KEY_NOTE_ID) != null) {
            // The note will be set in onResume()
            // See WordPress.deferredInit()
            mRestoredNoteId = savedInstanceState.getString(KEY_NOTE_ID);
        } else {
            SiteModel site = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
            CommentModel comment = (CommentModel) savedInstanceState.getSerializable(KEY_COMMENT);
            setComment(comment, site);
        }
    }
    setHasOptionsMenu(true);
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) CommentModel(org.wordpress.android.fluxc.model.CommentModel)

Example 14 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class NewBlogFragment method onSiteChanged.

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSiteChanged(OnSiteChanged event) {
    AppLog.i(T.NUX, event.toString());
    // Sites updated, we can finish this.
    if (getActivity() == null) {
        return;
    }
    endProgress();
    Intent intent = new Intent();
    SiteModel site = mSiteStore.getSiteBySiteId(mNewSiteRemoteId);
    intent.putExtra(SitePickerActivity.KEY_LOCAL_ID, site.getId());
    getActivity().setResult(Activity.RESULT_OK, intent);
    getActivity().finish();
}
Also used : Intent(android.content.Intent) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 15 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class SitePickerActivity method saveHiddenSites.

private void saveHiddenSites(Set<SiteRecord> changeSet) {
    boolean skippedCurrentSite = false;
    String currentSiteName = null;
    SiteList hiddenSites = getAdapter().getHiddenSites();
    List<SiteModel> siteList = new ArrayList<>();
    for (SiteRecord siteRecord : changeSet) {
        SiteModel siteModel = mSiteStore.getSiteByLocalId(siteRecord.localId);
        if (hiddenSites.contains(siteRecord)) {
            if (siteRecord.localId == mCurrentLocalId) {
                skippedCurrentSite = true;
                currentSiteName = siteRecord.getBlogNameOrHomeURL();
                continue;
            }
            siteModel.setIsVisible(false);
            // Remove stats data for hidden sites
            StatsTable.deleteStatsForBlog(this, siteRecord.localId);
        } else {
            siteModel.setIsVisible(true);
        }
        // Save the site
        mDispatcher.dispatch(SiteActionBuilder.newUpdateSiteAction(siteModel));
        siteList.add(siteModel);
    }
    updateVisibilityOfSitesOnRemote(siteList);
    // let user know the current site wasn't hidden
    if (skippedCurrentSite) {
        String cantHideCurrentSite = getString(R.string.site_picker_cant_hide_current_site);
        ToastUtils.showToast(this, String.format(cantHideCurrentSite, currentSiteName), ToastUtils.Duration.LONG);
    }
}
Also used : SiteList(org.wordpress.android.ui.main.SitePickerAdapter.SiteList) SiteRecord(org.wordpress.android.ui.main.SitePickerAdapter.SiteRecord) ArrayList(java.util.ArrayList) SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Aggregations

SiteModel (org.wordpress.android.fluxc.model.SiteModel)40 Intent (android.content.Intent)7 Subscribe (org.greenrobot.eventbus.Subscribe)5 View (android.view.View)4 Bundle (android.os.Bundle)3 TextView (android.widget.TextView)3 VolleyError (com.android.volley.VolleyError)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 ImageView (android.widget.ImageView)2 ScrollView (android.widget.ScrollView)2 RestRequest (com.wordpress.rest.RestRequest)2 CommentModel (org.wordpress.android.fluxc.model.CommentModel)2 PostModel (org.wordpress.android.fluxc.model.PostModel)2 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1