Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wordpress.android.models;

import android.content.Context;

public interface FilterCriteria {
String getLabel();
String getLabel(Context context);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.wordpress.android.models;

import android.content.Context;

import androidx.annotation.StringRes;

import org.wordpress.android.R;
import org.wordpress.android.WordPress;

public enum PeopleListFilter implements FilterCriteria {
TEAM(R.string.people_dropdown_item_team),
Expand All @@ -18,7 +19,7 @@
}

@Override
public String getLabel() {
return WordPress.getContext().getString(mLabelResId);
public String getLabel(Context context) {

Check notice

Code scanning / Android Lint

Nullable/NonNull annotation missing on method parameter Note

Missing null annotation
return context.getString(mLabelResId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.wordpress.android.models;

import android.content.Context;
import android.text.TextUtils;

import org.wordpress.android.ui.Organization;
Expand Down Expand Up @@ -243,7 +244,7 @@ public String getKeyString() {
* the label is the text displayed in the dropdown filter
*/
@Override
public String getLabel() {
public String getLabel(Context context) {
if (isTagDisplayNameAlphaNumeric()) {
return getTagDisplayName().toLowerCase(Locale.ROOT);
} else if (hasTagTitle()) {
Expand Down Expand Up @@ -282,7 +283,7 @@ public static ReaderTag createDiscoverPostCardsTag() {
public boolean equals(Object object) {
if (object instanceof ReaderTag) {
ReaderTag tag = (ReaderTag) object;
return (tag.tagType == this.tagType && tag.getLabel().equals(this.getLabel()));
return (tag.tagType == this.tagType && tag.getLabel(null).equals(this.getLabel(null)));
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ private void onSpinnerItemSelected(int position) {

if (mCurrentFilter == selectedCriteria) {
AppLog.d(mTAG, "The selected STATUS is already active: "
+ selectedCriteria.getLabel());
+ selectedCriteria.getLabel(getContext()));
return;
}

AppLog.d(mTAG, "NEW STATUS : " + selectedCriteria.getLabel());
AppLog.d(mTAG, "NEW STATUS : " + selectedCriteria.getLabel(getContext()));
setCurrentFilter(selectedCriteria);
if (mFilterListener != null) {
mFilterListener.onFilterSelected(position, selectedCriteria);
Expand Down Expand Up @@ -528,7 +528,7 @@ public View getView(int position, View convertView, ViewGroup parent) {

final TextView text = view.findViewById(R.id.text);
FilterCriteria selectedCriteria = (FilterCriteria) getItem(position);
text.setText(selectedCriteria.getLabel());
text.setText(selectedCriteria.getLabel(parent.getContext()));
if (mSpinnerTextColor != 0) {
text.setTextColor(mSpinnerTextColor);
}
Expand Down Expand Up @@ -557,7 +557,7 @@ public View getDropDownView(int position, View convertView, ViewGroup parent) {
holder = (TagViewHolder) convertView.getTag();
}

holder.mTextView.setText(selectedCriteria.getLabel());
holder.mTextView.setText(selectedCriteria.getLabel(parent.getContext()));
return convertView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void crossfadePreviewViews(@NonNull HistoryDetailContainerFragmentBindin
private void showHistoryTimeStampInToolbar(@NonNull Revision revision) {
ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setSubtitle(revision.getTimeSpan());
actionBar.setSubtitle(revision.getTimeSpan(requireContext()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.os.Parcelable
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.RawValue
import org.wordpress.android.WordPress
import android.content.Context
import org.wordpress.android.fluxc.model.revisions.Diff
import org.wordpress.android.fluxc.model.revisions.RevisionModel
import org.wordpress.android.ui.history.HistoryListItem.ViewType.FOOTER
Expand Down Expand Up @@ -46,8 +46,8 @@ sealed class HistoryListItem(val type: ViewType) {
@IgnoredOnParcel
private val postDate: Date = DateTimeUtils.dateUTCFromIso8601(postDateGmt?.replace(" ", "T"))

@IgnoredOnParcel
val timeSpan: String = DateTimeUtils.javaDateToTimeSpan(postDate, WordPress.getContext())
fun getTimeSpan(context: Context): String =
DateTimeUtils.javaDateToTimeSpan(postDate, context)

@IgnoredOnParcel
val formattedDate: String = postDate.toFormattedDateString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class FeedbackFormViewModel @Inject constructor(
private val feedbackFormUtils: FeedbackFormUtils,
private val mediaPickerLauncher: MediaPickerLauncher,
private val analyticsTrackerWrapper: AnalyticsTrackerWrapper,
private val contextProvider: org.wordpress.android.viewmodel.ContextProvider,
) : ScopedViewModel(mainDispatcher) {
private val _messageText = MutableStateFlow("")
val messageText = _messageText.asStateFlow()
Expand Down Expand Up @@ -297,7 +298,7 @@ class FeedbackFormViewModel @Inject constructor(

private fun showToast(@StringRes msgId: Int) {
viewModelScope.launch {
toastUtilsWrapper.showToast(msgId)
toastUtilsWrapper.showToast(contextProvider.getContext(), msgId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class NotificationsListViewModel @Inject constructor(
fun markNoteAsRead(context: Context, notes: List<Note>) = launch {
if (networkUtilsWrapper.isNetworkAvailable().not()) {
withContext(mainDispatcher) {
toastUtilsWrapper.showToast(R.string.error_network_connection)
toastUtilsWrapper.showToast(context, R.string.error_network_connection)
}
return@launch
}
Expand All @@ -115,7 +115,7 @@ class NotificationsListViewModel @Inject constructor(
notificationsTableWrapper.saveNotes(revertedNotes, false)
eventBusWrapper.post(NotificationsChanged())
withContext(mainDispatcher) {
toastUtilsWrapper.showToast(R.string.error_generic)
toastUtilsWrapper.showToast(context, R.string.error_generic)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class PostListDialogHelper(
private val checkNetworkConnection: () -> Boolean,
private val analyticsTracker: AnalyticsTrackerWrapper,
private val showConflictResolutionOverlay: ((PostResolutionOverlayActionEvent.ShowDialogAction) -> Unit)? = null,
private val isPostConflictResolutionEnabled: Boolean
private val isPostConflictResolutionEnabled: Boolean,
private val getContext: () -> android.content.Context
) {
// Since we are using DialogFragments we need to hold onto which post will be published or trashed / resolved
private var localPostIdForDeleteDialog: Int? = null
Expand Down Expand Up @@ -129,7 +130,7 @@ class PostListDialogHelper(
val dialogHolder = DialogHolder(
tag = CONFIRM_ON_CONFLICT_LOAD_REMOTE_POST_DIALOG_TAG,
title = UiStringRes(R.string.dialog_confirm_load_remote_post_title),
message = UiStringText(PostUtils.getConflictedPostCustomStringForDialog(post)),
message = UiStringText(PostUtils.getConflictedPostCustomStringForDialog(getContext(), post)),
positiveButton = UiStringRes(R.string.dialog_confirm_load_remote_post_discard_local),
negativeButton = UiStringRes(R.string.dialog_confirm_load_remote_post_discard_web)
)
Expand All @@ -150,7 +151,7 @@ class PostListDialogHelper(
val dialogHolder = DialogHolder(
tag = CONFIRM_ON_AUTOSAVE_REVISION_DIALOG_TAG,
title = UiStringRes(R.string.dialog_confirm_autosave_title),
message = PostUtils.getCustomStringForAutosaveRevisionDialog(post),
message = PostUtils.getCustomStringForAutosaveRevisionDialog(getContext(), post),
positiveButton = UiStringRes(R.string.dialog_confirm_autosave_restore_button),
negativeButton = UiStringRes(R.string.dialog_confirm_autosave_dont_restore_button)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class PostListMainViewModel @Inject constructor(
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
private val uploadStarter: UploadStarter,
private val postConflictResolutionFeatureUtils: PostConflictResolutionFeatureUtils,
private val postConflictDetector: PostConflictDetector
private val postConflictDetector: PostConflictDetector,
private val contextProvider: org.wordpress.android.viewmodel.ContextProvider
) : ViewModel(), CoroutineScope {
private var isStarted = false

Expand Down Expand Up @@ -160,7 +161,8 @@ class PostListMainViewModel @Inject constructor(
showConflictResolutionOverlay = { _conflictResolutionAction.postValue(it) },
checkNetworkConnection = this::checkNetworkConnection,
analyticsTracker = analyticsTracker,
isPostConflictResolutionEnabled = postConflictResolutionFeatureUtils.isPostConflictResolutionEnabled()
isPostConflictResolutionEnabled = postConflictResolutionFeatureUtils.isPostConflictResolutionEnabled(),
getContext = { contextProvider.getContext() }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.apache.commons.lang3.StringUtils;
import org.greenrobot.eventbus.EventBus;
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.fluxc.model.MediaModel;
import org.wordpress.android.fluxc.model.PostImmutableModel;
Expand Down Expand Up @@ -307,14 +306,14 @@ public static String removeWPVideoPress(String str) {
return str.replaceAll("(?s)\\n?<!--\\swp:video.*?(.*?)wp:video.*?\\s-->", "");
}

public static String getFormattedDate(PostModel post) {
public static String getFormattedDate(Context context, PostModel post) {
if (PostStatus.fromPost(post) == PostStatus.SCHEDULED) {
return DateUtils.formatDateTime(WordPress.getContext(),
return DateUtils.formatDateTime(context,
DateTimeUtils.timestampFromIso8601Millis(post.getDateCreated()),
DateUtils.FORMAT_ABBREV_ALL);
} else {
return DateTimeUtils.javaDateToTimeSpan(DateTimeUtils.dateUTCFromIso8601(post.getDateCreated()),
WordPress.getContext());
context);
}
}

Expand Down Expand Up @@ -480,8 +479,7 @@ public static boolean hasAutoSave(PostModel post) {
&& post.hasUnpublishedRevision();
}

public static String getConflictedPostCustomStringForDialog(PostModel post) {
Context context = WordPress.getContext();
public static String getConflictedPostCustomStringForDialog(Context context, PostModel post) {
String firstPart = context.getString(R.string.dialog_confirm_load_remote_post_body);
String lastModified =
TextUtils.isEmpty(post.getDateLocallyChanged()) ? post.getLastModified() : post.getDateLocallyChanged();
Expand All @@ -494,8 +492,7 @@ public static String getConflictedPostCustomStringForDialog(PostModel post) {
return firstPart + secondPart;
}

public static UiStringText getCustomStringForAutosaveRevisionDialog(PostModel post) {
Context context = WordPress.getContext();
public static UiStringText getCustomStringForAutosaveRevisionDialog(Context context, PostModel post) {
String firstPart = post.isPage() ? context.getString(R.string.dialog_confirm_autosave_body_first_part_for_page)
: context.getString(R.string.dialog_confirm_autosave_body_first_part);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ class PostsListActivity : BaseAppCompatActivity(),

fabButton.redirectContextClickToLongPressListener()

postsPagerAdapter = PostsPagerAdapter(POST_LIST_PAGES, site, supportFragmentManager)
postsPagerAdapter = PostsPagerAdapter(
this@PostsListActivity, POST_LIST_PAGES, site, supportFragmentManager
)
postPager.adapter = postsPagerAdapter
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ package org.wordpress.android.ui.posts
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import org.wordpress.android.WordPress
import android.content.Context
import org.wordpress.android.fluxc.model.SiteModel
import java.lang.ref.WeakReference

@Suppress("DEPRECATION")
class PostsPagerAdapter(
private val context: Context,
private val pages: List<PostListType>,
private val site: SiteModel,
val fm: FragmentManager
Expand All @@ -29,7 +30,7 @@ class PostsPagerAdapter(
}

override fun getPageTitle(position: Int): CharSequence? =
WordPress.getContext().getString(pages[position].titleResId)
context.getString(pages[position].titleResId)

fun getItemAtPosition(position: Int): PostListFragment? {
return listFragments[position]?.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ public void onCredentialsValidated(Exception error) {
return;
}
if (error != null) {
ToastUtils.showToast(WordPress.getContext(), R.string.username_or_password_incorrect);
ToastUtils.showToast(getActivity(), R.string.username_or_password_incorrect);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public void onFetchError(Exception error) {
@Override
public void onSaveError(Exception error) {
if (isAdded()) {
ToastUtils.showToast(WordPress.getContext(), R.string.error_post_remote_site_settings);
ToastUtils.showToast(getActivity(), R.string.error_post_remote_site_settings);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private void performAddTag(final String tagName) {
getPageAdapter().refreshFollowedTagFragment();

if (succeeded) {
showInfoSnackbar(getString(R.string.reader_label_added_tag, tag.getLabel()));
showInfoSnackbar(getString(R.string.reader_label_added_tag, tag.getLabel(this)));
mLastAddedTagName = tag.getTagSlug();
mReaderTracker.trackTag(
AnalyticsTracker.Stat.READER_TAG_FOLLOWED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ public void onClick(View view) {
} else {
dtPublished = DateTimeUtils.dateFromIso8601(comment.getPublished());
}
commentHolder.mTxtDate.setText(DateTimeUtils.javaDateToTimeSpan(dtPublished, WordPress.getContext()));
commentHolder.mTxtDate.setText(
DateTimeUtils.javaDateToTimeSpan(dtPublished, commentHolder.itemView.getContext()));

String avatarUrl = WPAvatarUtils.rewriteAvatarUrl(comment.getAuthorAvatar(), mAvatarSz);
mImageManager.loadIntoCircle(commentHolder.mImgAvatar, ImageType.AVATAR, avatarUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private void renderTagHeader(
};

ReaderTagHeaderUiState uiState = new ReaderTagHeaderUiState(
currentTag.getLabel(),
currentTag.getLabel(tagHolder.itemView.getContext()),
new FollowButtonUiState(
onFollowButtonClicked,
ReaderTagTable.isFollowedTagName(currentTag.getTagSlug()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public ReaderTagList getSubscribedItems() {
@Override
public void onBindViewHolder(TagViewHolder holder, int position) {
final ReaderTag tag = mTags.get(position);
holder.mTxtTagName.setText(tag.getLabel());
holder.mTxtTagName.setText(tag.getLabel(holder.itemView.getContext()));
holder.mRemoveFollowButton.setOnClickListener(view -> performDeleteTag(tag, holder.mRemoveFollowButton));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ sealed class SubfilterListItem(val type: ItemType, val isTrackedItem: Boolean =
override val onClickAction: (filter: SubfilterListItem) -> Unit,
val tag: ReaderTag
) : SubfilterListItem(TAG, true) {
override val label: UiString = UiStringText(tag.label)
override val label: UiString = UiStringText(tag.getLabel(null))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class ReaderViewModel @Inject constructor(
private val readerTopBarMenuHelper: ReaderTopBarMenuHelper,
private val urlUtilsWrapper: UrlUtilsWrapper,
private val readerTagsFeedFeatureConfig: ReaderTagsFeedFeatureConfig,
private val contextProvider: org.wordpress.android.viewmodel.ContextProvider,
) : ScopedViewModel(mainDispatcher) {
private var initialized: Boolean = false
private var wasPaused: Boolean = false
Expand Down Expand Up @@ -129,7 +130,9 @@ class ReaderViewModel @Inject constructor(
updateReaderTagsList(tagList)
updateTopBarUiState(savedInstanceState)
_uiState.value = ContentUiState(
tabUiStates = tagList.map { TabUiState(label = UiStringText(it.label)) },
tabUiStates = tagList.map {
TabUiState(label = UiStringText(it.getLabel(contextProvider.getContext())))
},
selectedReaderTag = selectedReaderTag(),
)
if (!initialized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AddSubscribersViewModel @Inject constructor(
private val appLogWrapper: AppLogWrapper,
private val toastUtilsWrapper: ToastUtilsWrapper,
private val trackNetworkRequestsInterceptor: TrackNetworkRequestsInterceptor,
private val contextProvider: org.wordpress.android.viewmodel.ContextProvider,
) : ScopedViewModel(bgDispatcher) {
@Inject
@Named(IO_THREAD)
Expand Down Expand Up @@ -66,10 +67,10 @@ class AddSubscribersViewModel @Inject constructor(
val result = addSubscribers(emails)
withContext(mainDispatcher) {
if (result.isSuccess) {
toastUtilsWrapper.showToast(R.string.subscribers_add_success)
toastUtilsWrapper.showToast(contextProvider.getContext(), R.string.subscribers_add_success)
onSuccess()
} else {
toastUtilsWrapper.showToast(R.string.subscribers_add_failed)
toastUtilsWrapper.showToast(contextProvider.getContext(), R.string.subscribers_add_failed)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.wordpress.android.util

import android.content.Context
import androidx.annotation.StringRes
import dagger.Reusable
import org.wordpress.android.WordPress
import javax.inject.Inject

@Reusable
class ToastUtilsWrapper @Inject constructor() {
fun showToast(@StringRes messageRes: Int) =
ToastUtils.showToast(WordPress.getContext(), messageRes)
fun showToast(context: Context, @StringRes messageRes: Int) =
ToastUtils.showToast(context, messageRes)
}
Loading