Skip to content

Commit

Permalink
Merge branch 'trunk' into issue/20535-fix-crash-on-featured-image-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
irfano committed May 17, 2024
2 parents 62250f0 + a32269a commit b5bd863
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 44 deletions.
39 changes: 39 additions & 0 deletions .aiexclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# OS X generated file
.DS_Store

# Build-related files
fastlane/

# Key-related files
.jks
.keystore

# Backup files
.bak

# Generated files
bin/
gen/
build/
build.log

# Built application files
.apk
.ap_
.aab

# Dex VM files
.dex

# Configuration files
.configure
.configure-files/
google-services.json
google-upload-credentials.json
firebase.secrets.json
sentry.properties

# Gradle files
gradle.properties
local.properties
local-builds.gradle
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [*] Fixed a rare crash on Posts List screen [https://github.com/wordpress-mobile/WordPress-Android/pull/20813]
* [*] Fixed a rare crash on the Login screen [https://github.com/wordpress-mobile/WordPress-Android/pull/20821]
* [*] Fixed a rare crash on the featured image confirmation dialog [https://github.com/wordpress-mobile/WordPress-Android/pull/20836]
* [*] Fixed an ANR issue on the Post List screen [https://github.com/wordpress-mobile/WordPress-Android/pull/20833]

24.9
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.content.Context;
import android.icu.text.CompactDecimalFormat;
import android.icu.text.NumberFormat;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -31,6 +33,9 @@
import org.wordpress.android.util.image.BlavatarShape;
import org.wordpress.android.util.image.ImageManager;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.inject.Inject;

/**
Expand All @@ -55,6 +60,9 @@ public interface OnBlogInfoLoadedListener {
private OnBlogInfoLoadedListener mBlogInfoListener;
private OnFollowListener mFollowListener;

private final ExecutorService mExecutorService = Executors.newSingleThreadExecutor();
private final Handler mMainHandler = new Handler(Looper.getMainLooper());

@Inject AccountStore mAccountStore;
@Inject ImageManager mImageManager;
@Inject ReaderTracker mReaderTracker;
Expand Down Expand Up @@ -103,41 +111,42 @@ public void loadBlogInfo(
mBlogId = blogId;
mFeedId = feedId;

final ReaderBlog localBlogInfo;
if (blogId == 0 && feedId == 0) {
ToastUtils.showToast(getContext(), R.string.reader_toast_err_show_blog);
return;
}

mIsFeed = ReaderUtils.isExternalFeed(mBlogId, mFeedId);

if (mIsFeed) {
localBlogInfo = ReaderBlogTable.getFeedInfo(mFeedId);
} else {
localBlogInfo = ReaderBlogTable.getBlogInfo(mBlogId);
}

if (localBlogInfo != null) {
showBlogInfo(localBlogInfo, source);
}

// then get from server if doesn't exist locally or is time to update it
if (localBlogInfo == null || ReaderBlogTable.isTimeToUpdateBlogInfo(localBlogInfo)) {
ReaderActions.UpdateBlogInfoListener listener = new ReaderActions.UpdateBlogInfoListener() {
@Override
public void onResult(ReaderBlog serverBlogInfo) {
if (isAttachedToWindow()) {
showBlogInfo(serverBlogInfo, source);
}
}
};

// run in background to avoid ANR
mExecutorService.execute(() -> {
final ReaderBlog localBlogInfo;
if (mIsFeed) {
ReaderBlogActions.updateFeedInfo(mFeedId, null, listener);
localBlogInfo = ReaderBlogTable.getFeedInfo(mFeedId);
} else {
ReaderBlogActions.updateBlogInfo(mBlogId, null, listener);
localBlogInfo = ReaderBlogTable.getBlogInfo(mBlogId);
}
}

mMainHandler.post(() -> {
if (localBlogInfo != null) {
showBlogInfo(localBlogInfo, source);
}
// then get from server if doesn't exist locally or is time to update it
if (localBlogInfo == null || ReaderBlogTable.isTimeToUpdateBlogInfo(localBlogInfo)) {
ReaderActions.UpdateBlogInfoListener listener = serverBlogInfo -> {
if (isAttachedToWindow()) {
showBlogInfo(serverBlogInfo, source);
}
};

if (mIsFeed) {
ReaderBlogActions.updateFeedInfo(mFeedId, null, listener);
} else {
ReaderBlogActions.updateBlogInfo(mBlogId, null, listener);
}
}
});
});
}

private void showBlogInfo(ReaderBlog blogInfo, String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,10 @@ class SiteCreationMainVM @Inject constructor(
_onCompleted.value = NotCreated to isSiteTitleTaskCompleted()
}

fun onWizardFinished(result: Created) {
siteCreationState = siteCreationState.copy(result = result)
_onCompleted.value = result to isSiteTitleTaskCompleted()
fun onWizardFinished(result: Created?) {
val nullCheckedResult = result ?: NotCreated
siteCreationState = siteCreationState.copy(result = nullCheckedResult)
_onCompleted.value = nullCheckedResult to isSiteTitleTaskCompleted()
}

private fun isSiteTitleTaskCompleted() = !siteCreationState.siteName.isNullOrBlank()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ class SitePreviewViewModel @Inject constructor(
private var siteDesign: String? = null
private var isFree: Boolean = true

private lateinit var result: Created
private lateinit var domainName: String
private var result: Created? = null

private val _uiState: MutableLiveData<SitePreviewUiState> = MutableLiveData()
val uiState: LiveData<SitePreviewUiState> = _uiState

private val _preloadPreview: MutableLiveData<String> = MutableLiveData()
val preloadPreview: LiveData<String> = _preloadPreview

private val _onOkButtonClicked = SingleLiveEvent<Created>()
val onOkButtonClicked: LiveData<Created> = _onOkButtonClicked
private val _onOkButtonClicked = SingleLiveEvent<Created?>()
val onOkButtonClicked: LiveData<Created?> = _onOkButtonClicked

fun start(siteCreationState: SiteCreationState) {
if (isStarted) return else isStarted = true
Expand All @@ -90,12 +89,13 @@ class SitePreviewViewModel @Inject constructor(
siteDesign = siteCreationState.siteDesign
result = siteCreationState.result
isFree = requireNotNull(siteCreationState.domain).isFree
domainName = getCleanUrl(result.site.url) ?: ""
startPreLoadingWebView()
if (result is CreatedButNotFetched) {
launch {
fetchNewlyCreatedSiteModel(result.site.siteId)?.let {
result = Completed(it)
result?.let {
if (it is CreatedButNotFetched) {
launch {
fetchNewlyCreatedSiteModel(it.site.siteId)?.let {
result = Completed(it)
}
}
}
}
Expand All @@ -121,7 +121,7 @@ class SitePreviewViewModel @Inject constructor(
}
}
// Load the newly created site in the webview
result.site.url?.let { url ->
result?.site?.url?.let { url ->
val urlToLoad = urlUtils.addUrlSchemeIfNeeded(
url = url,
addHttps = isWordPressComSubDomain(url)
Expand Down Expand Up @@ -172,7 +172,7 @@ class SitePreviewViewModel @Inject constructor(
private fun getCleanUrl(url: String) = StringUtils.removeTrailingSlash(urlUtils.removeScheme(url))

private fun createSitePreviewData(): UrlData {
val url = domainName
val url = result?.let { getCleanUrl(it.site.url) ?: "" } ?: ""
val subDomain = urlUtils.extractSubDomain(url)
val fullUrl = urlUtils.addUrlSchemeIfNeeded(url, true)
val subDomainIndices = 0 to subDomain.length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class SitePreviewViewModelTest : BaseUnitTest() {
private lateinit var uiStateObserver: Observer<SitePreviewUiState>

@Mock
private lateinit var onOkClickedObserver: Observer<Created>
private lateinit var onOkClickedObserver: Observer<Created?>

@Mock
private lateinit var preloadPreviewObserver: Observer<String>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ext {
automatticAboutVersion = '1.4.0'
automatticRestVersion = '1.0.8'
automatticTracksVersion = '5.0.0'
gutenbergMobileVersion = 'v1.118.0'
gutenbergMobileVersion = 'v1.119.0-alpha1'
wordPressAztecVersion = 'v2.1.3'
wordPressFluxCVersion = '2.79.0'
wordPressLoginVersion = '1.15.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,8 @@ private ArrayList<MediaOption> initOtherMediaImageOptions() {

Bundle arguments = getArguments();
FragmentActivity activity = getActivity();
if (activity == null || arguments == null) {
final Context context = getContext();
if (activity == null || context == null || arguments == null) {
AppLog.e(T.EDITOR,
"Failed to initialize other media options because the activity or getArguments() is null");
return otherMediaOptions;
Expand All @@ -710,13 +711,13 @@ private ArrayList<MediaOption> initOtherMediaImageOptions() {
String packageName = activity.getApplication().getPackageName();
if (supportStockPhotos) {
int stockMediaResourceId =
getResources().getIdentifier("photo_picker_stock_media", "string", packageName);
context.getResources().getIdentifier("photo_picker_stock_media", "string", packageName);

otherMediaOptions.add(new MediaOption(MEDIA_SOURCE_STOCK_MEDIA, getString(stockMediaResourceId)));
}
if (supportsTenor) {
int gifMediaResourceId =
getResources().getIdentifier("photo_picker_gif", "string", packageName);
context.getResources().getIdentifier("photo_picker_gif", "string", packageName);
otherMediaOptions.add(new MediaOption(GIF_MEDIA, getString(gifMediaResourceId)));
}

Expand Down

0 comments on commit b5bd863

Please sign in to comment.