use of org.wordpress.android.fluxc.model.PostFormatModel in project WordPress-Android by wordpress-mobile.
the class EditPostSettingsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.edit_post_settings_fragment, container, false);
if (rootView == null || mPost == null) {
return null;
}
Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
mExcerptEditText = (EditText) rootView.findViewById(R.id.postExcerpt);
mPasswordEditText = (EditText) rootView.findViewById(R.id.post_password);
mPubDateText = (TextView) rootView.findViewById(R.id.pubDate);
mPubDateText.setOnClickListener(this);
mStatusSpinner = (Spinner) rootView.findViewById(R.id.status);
mStatusSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
updatePostSettingsAndSaveButton();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
mSectionCategories = ((ViewGroup) rootView.findViewById(R.id.sectionCategories));
TextView featuredImageLabel = (TextView) rootView.findViewById(R.id.featuredImageLabel);
mFeaturedImageView = (NetworkImageView) rootView.findViewById(R.id.featuredImage);
mFeaturedImageButton = (Button) rootView.findViewById(R.id.addFeaturedImage);
if (AppPrefs.isVisualEditorEnabled() || AppPrefs.isAztecEditorEnabled()) {
registerForContextMenu(mFeaturedImageView);
mFeaturedImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
view.showContextMenu();
}
});
mFeaturedImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
launchMediaGalleryActivity();
}
});
} else {
featuredImageLabel.setVisibility(View.GONE);
mFeaturedImageView.setVisibility(View.GONE);
mFeaturedImageButton.setVisibility(View.GONE);
}
if (mPost.isPage()) {
// remove post specific views
mExcerptEditText.setVisibility(View.GONE);
rootView.findViewById(R.id.sectionTags).setVisibility(View.GONE);
rootView.findViewById(R.id.sectionCategories).setVisibility(View.GONE);
rootView.findViewById(R.id.postFormatLabel).setVisibility(View.GONE);
rootView.findViewById(R.id.postFormat).setVisibility(View.GONE);
} else {
// Default values
mPostFormatKeys = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.post_format_keys)));
mPostFormatNames = new ArrayList<>(Arrays.asList(getResources().getStringArray(R.array.post_format_display_names)));
// If we have specific values for this site, use them
List<PostFormatModel> postFormatModels = mSiteStore.getPostFormats(mSite);
for (PostFormatModel postFormatModel : postFormatModels) {
if (!mPostFormatKeys.contains(postFormatModel.getSlug())) {
mPostFormatKeys.add(postFormatModel.getSlug());
mPostFormatNames.add(postFormatModel.getDisplayName());
}
}
// Set up the Post Format spinner
mPostFormatSpinner = (Spinner) rootView.findViewById(R.id.postFormat);
ArrayAdapter<String> pfAdapter = new ArrayAdapter<>(getActivity(), R.layout.simple_spinner_item, mPostFormatNames);
pfAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mPostFormatSpinner.setAdapter(pfAdapter);
String activePostFormat = POST_FORMAT_STANDARD_KEY;
if (!TextUtils.isEmpty(mPost.getPostFormat())) {
activePostFormat = mPost.getPostFormat();
}
for (int i = 0; i < mPostFormatKeys.size(); i++) {
if (mPostFormatKeys.get(i).equals(activePostFormat))
mPostFormatSpinner.setSelection(i);
}
mPostFormatSpinner.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
return false;
}
});
mTagsEditText = (SuggestionAutoCompleteText) rootView.findViewById(R.id.tags);
if (mTagsEditText != null) {
mTagsEditText.setTokenizer(new SuggestionAutoCompleteText.CommaTokenizer());
setupSuggestionServiceAndAdapter();
}
}
initSettingsFields();
populateSelectedCategories();
initLocation(rootView);
return rootView;
}
use of org.wordpress.android.fluxc.model.PostFormatModel in project WordPress-Android by wordpress-mobile.
the class SiteSettingsInterface method getFormats.
@NonNull
public Map<String, String> getFormats() {
mSettings.postFormats = new HashMap<>();
String[] postFormatDisplayNames = mActivity.getResources().getStringArray(R.array.post_format_display_names);
String[] postFormatKeys = mActivity.getResources().getStringArray(R.array.post_format_keys);
// Add standard post format (only for .com)
mSettings.postFormats.put(STANDARD_POST_FORMAT_KEY, STANDARD_POST_FORMAT);
// Add default post formats
for (int i = 0; i < postFormatKeys.length && i < postFormatDisplayNames.length; ++i) {
mSettings.postFormats.put(postFormatKeys[i], postFormatDisplayNames[i]);
}
if (mSite == null) {
return mSettings.postFormats;
}
// Add (or replace) site-specific post formats
List<PostFormatModel> postFormats = mSiteStore.getPostFormats(mSite);
for (PostFormatModel postFormat : postFormats) {
mSettings.postFormats.put(postFormat.getSlug(), postFormat.getDisplayName());
}
return mSettings.postFormats;
}
Aggregations