Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to gradle 6 #12896

Merged
merged 23 commits into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e612da1
Upgrade Gradle to 6
oguzkocer Sep 13, 2020
47418a2
Upgrade utils to Gradle 6
oguzkocer Sep 13, 2020
fb21c8b
Update gradle wrapper files for main project for Gradle 6
oguzkocer Sep 13, 2020
7841818
Adds useAndroidX to WordPressUtils gradle properties example
oguzkocer Sep 13, 2020
faab3d6
Remove unused layouts
planarvoid Sep 14, 2020
734cd3a
Replace LifecycleOwner parent with a lifecycleOwner field
planarvoid Sep 14, 2020
33cba6f
Replace LifecycleOwner parent with a lifecycleOwner field
planarvoid Sep 14, 2020
6044402
Replace context with resource provider in photo picker
planarvoid Sep 14, 2020
6732b57
Replace LifecycleOwner parent with a lifecycleOwner field
planarvoid Sep 14, 2020
35fedbb
Duplicate method with ResourceProvider instead of context
planarvoid Sep 14, 2020
f9c5228
Replace LifecycleOwner parent with a lifecycleOwner field
planarvoid Sep 14, 2020
f95935d
Replace ToggleButton with AppCompatToggleButton as parent of RippleTo…
planarvoid Sep 14, 2020
06c7191
Replace LifecycleOwner parent with a lifecycleOwner field
planarvoid Sep 14, 2020
bde2e39
Replace LifecycleOwner parent with a lifecycleOwner field
planarvoid Sep 14, 2020
34f4e2c
Removes extra parameter from MediaPicker and PhotoPicker VM tests
oguzkocer Sep 14, 2020
556e314
Update stories-android hash for gradle 6 upgrade
oguzkocer Sep 15, 2020
8e84f16
Changes from latest Android Studio for .idea/codeStyles/Project.xml
oguzkocer Sep 15, 2020
76ceec4
Merge remote-tracking branch 'origin/develop' into oguz/upgrade-to-gr…
oguzkocer Sep 15, 2020
f0554c7
Increase CI memory to 2048m
oguzkocer Sep 15, 2020
a8d9b97
Sets up gradle-bintray-plugin to publish utils library
oguzkocer Sep 15, 2020
a5e62fc
Updates utils README for the updated Bintray publish instructions
oguzkocer Sep 15, 2020
e0a6eaa
Use all distribution-type for gradlew
oguzkocer Sep 15, 2020
370f2eb
Update libs/stories to Gradle 6 upgrade merge commit
oguzkocer Sep 16, 2020
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ commands:
steps:
- run:
name: Setup gradle.properties
command: cp gradle.properties-example gradle.properties
command: cp gradle.properties-example gradle.properties && cp libs/utils/WordPressUtils/gradle.properties-example libs/utils/WordPressUtils/gradle.properties
update-gradle-memory:
steps:
- run:
name: Update memory setting
command: sed -i "s/org.gradle.jvmargs=.*/org.gradle.jvmargs=-Xmx1537m -XX:+HeapDumpOnOutOfMemoryError -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false /" gradle.properties
command: sed -i "s/org.gradle.jvmargs=.*/org.gradle.jvmargs=-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError -Dkotlin.compiler.execution.strategy=in-process -Dkotlin.incremental=false /" gradle.properties
npm-install:
steps:
- restore_cache:
Expand Down
11 changes: 10 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ android {
}

compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolVersion

defaultConfig {
applicationId "org.wordpress.android"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.wordpress.android.ui.mediapicker

import android.Manifest.permission
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.CoroutineDispatcher
Expand Down Expand Up @@ -63,7 +62,6 @@ class MediaPickerViewModel @Inject constructor(
private val analyticsUtilsWrapper: AnalyticsUtilsWrapper,
private val analyticsTrackerWrapper: AnalyticsTrackerWrapper,
private val permissionsHandler: PermissionsHandler,
private val context: Context,
private val localeManagerWrapper: LocaleManagerWrapper,
private val mediaUtilsWrapper: MediaUtilsWrapper,
private val resourceProvider: ResourceProvider
Expand Down Expand Up @@ -394,7 +392,7 @@ class MediaPickerViewModel @Inject constructor(
val label = if (softAskRequest.isAlwaysDenied) {
val permissionName = ("<strong>${
WPPermissionUtils.getPermissionName(
context,
resourceProvider,
permission.WRITE_EXTERNAL_STORAGE
)
}</strong>")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.wordpress.android.ui.photopicker

import android.Manifest.permission
import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import kotlinx.coroutines.CoroutineDispatcher
Expand Down Expand Up @@ -69,7 +68,6 @@ class PhotoPickerViewModel @Inject constructor(
private val analyticsTrackerWrapper: AnalyticsTrackerWrapper,
private val permissionsHandler: PermissionsHandler,
private val tenorFeatureConfig: TenorFeatureConfig,
private val context: Context,
private val resourceProvider: ResourceProvider
) : ScopedViewModel(mainDispatcher) {
private val _navigateToPreview = MutableLiveData<Event<UriWrapper>>()
Expand Down Expand Up @@ -443,7 +441,7 @@ class PhotoPickerViewModel @Inject constructor(
val appName = "<strong>${resourceProvider.getString(R.string.app_name)}</strong>"
val label = if (softAskRequest.isAlwaysDenied) {
val permissionName = ("<strong>${WPPermissionUtils.getPermissionName(
context,
resourceProvider,
permission.WRITE_EXTERNAL_STORAGE
)}</strong>")
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ class PostListMainViewModel @Inject constructor(
@Named(UI_THREAD) private val mainDispatcher: CoroutineDispatcher,
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
private val uploadStarter: UploadStarter
) : ViewModel(), LifecycleOwner, CoroutineScope {
private val lifecycleRegistry = LifecycleRegistry(this)
override fun getLifecycle(): Lifecycle = lifecycleRegistry
) : ViewModel(), CoroutineScope {
private val lifecycleOwner = object : LifecycleOwner {
val lifecycleRegistry = LifecycleRegistry(this)
override fun getLifecycle(): Lifecycle {
return lifecycleRegistry
}
}

private val scrollToTargetPostJob: Job = Job()
override val coroutineContext: CoroutineContext
Expand Down Expand Up @@ -161,7 +165,7 @@ class PostListMainViewModel @Inject constructor(
private val featuredImageTracker = PostListFeaturedImageTracker(dispatcher = dispatcher, mediaStore = mediaStore)

private val postFetcher by lazy {
PostFetcher(lifecycle, dispatcher)
PostFetcher(lifecycleOwner.lifecycle, dispatcher)
}

private val postListDialogHelper: PostListDialogHelper by lazy {
Expand Down Expand Up @@ -217,7 +221,7 @@ class PostListMainViewModel @Inject constructor(
}

init {
lifecycleRegistry.markState(Lifecycle.State.CREATED)
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.CREATED
}

fun start(
Expand All @@ -243,7 +247,7 @@ class PostListMainViewModel @Inject constructor(
}

postListEventListenerFactory.createAndStartListening(
lifecycle = lifecycle,
lifecycle = lifecycleOwner.lifecycle,
dispatcher = dispatcher,
bgDispatcher = bgDispatcher,
postStore = postStore,
Expand Down Expand Up @@ -283,19 +287,19 @@ class PostListMainViewModel @Inject constructor(
}
}

lifecycleRegistry.markState(Lifecycle.State.STARTED)
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.STARTED

uploadStarter.queueUploadFromSite(site)

editPostRepository.run {
postChanged.observe(this@PostListMainViewModel, Observer {
postChanged.observe(lifecycleOwner, Observer {
savePostToDbUseCase.savePostToDb(editPostRepository, site)
})
}
}

override fun onCleared() {
lifecycleRegistry.markState(Lifecycle.State.DESTROYED)
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
scrollToTargetPostJob.cancel() // cancels all coroutines with the default coroutineContext
super.onCleared()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ class StoryComposerViewModel @Inject constructor(
private val setUntitledStoryTitleIfTitleEmptyUseCase: SetUntitledStoryTitleIfTitleEmptyUseCase,
private val postEditorAnalyticsSessionWrapper: PostEditorAnalyticsSessionWrapper,
private val dispatcher: Dispatcher
) : ViewModel(), LifecycleOwner {
private val lifecycleRegistry = LifecycleRegistry(this)
override fun getLifecycle(): Lifecycle = lifecycleRegistry
) : ViewModel() {
private val lifecycleOwner = object : LifecycleOwner {
val lifecycleRegistry = LifecycleRegistry(this)
override fun getLifecycle(): Lifecycle = lifecycleRegistry
}

private lateinit var editPostRepository: EditPostRepository
private lateinit var site: SiteModel
Expand All @@ -53,7 +55,7 @@ class StoryComposerViewModel @Inject constructor(
val submitButtonClicked: LiveData<Event<Unit>> = _submitButtonClicked

init {
lifecycleRegistry.currentState = Lifecycle.State.CREATED
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.CREATED
}

private val _trackEditorCreatedPost = MutableLiveData<Event<Unit>>()
Expand Down Expand Up @@ -84,7 +86,7 @@ class StoryComposerViewModel @Inject constructor(
systemNotificationsTracker.trackTappedNotification(it)
}

lifecycleRegistry.currentState = Lifecycle.State.STARTED
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.STARTED
updateStoryPostWithChanges()
}

Expand Down Expand Up @@ -119,7 +121,7 @@ class StoryComposerViewModel @Inject constructor(
}

private fun updateStoryPostWithChanges() {
editPostRepository.postChanged.observe(this, Observer {
editPostRepository.postChanged.observe(lifecycleOwner, Observer {
savePostToDbUseCase.savePostToDb(editPostRepository, site)
})
}
Expand Down Expand Up @@ -149,7 +151,7 @@ class StoryComposerViewModel @Inject constructor(

override fun onCleared() {
super.onCleared()
lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
postEditorAnalyticsSession.end()
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.wordpress.android.util;

import android.Manifest;
import android.Manifest.permission;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -21,6 +20,7 @@
import org.wordpress.android.R;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.ui.prefs.AppPrefs;
import org.wordpress.android.viewmodel.ResourceProvider;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -170,6 +170,24 @@ public static String getPermissionName(@NonNull Context context, @NonNull String
}
}

/*
* returns the name to display for a permission, ex: "permission.WRITE_EXTERNAL_STORAGE" > "Storage"
*/
public static String getPermissionName(@NonNull ResourceProvider resourceProvider, @NonNull String permission) {
switch (permission) {
case android.Manifest.permission.WRITE_EXTERNAL_STORAGE:
case android.Manifest.permission.READ_EXTERNAL_STORAGE:
return resourceProvider.getString(R.string.permission_storage);
case android.Manifest.permission.CAMERA:
return resourceProvider.getString(R.string.permission_camera);
case Manifest.permission.RECORD_AUDIO:
return resourceProvider.getString(R.string.permission_microphone);
default:
AppLog.w(AppLog.T.UTILS, "No name for requested permission");
return resourceProvider.getString(R.string.unknown);
}
}

/*
* called when the app detects that the user has permanently denied a permission, shows a dialog
* alerting them to this fact and enabling them to visit the app settings to edit permissions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class HistoryViewModel @Inject constructor(
@Named(UI_THREAD) uiDispatcher: CoroutineDispatcher,
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
private val connectionStatus: LiveData<ConnectionStatus>
) : ScopedViewModel(uiDispatcher), LifecycleOwner {
) : ScopedViewModel(uiDispatcher) {
enum class HistoryListStatus {
DONE,
ERROR,
Expand Down Expand Up @@ -75,11 +75,15 @@ class HistoryViewModel @Inject constructor(
private val _post = MutableLiveData<PostModel?>()
val post: LiveData<PostModel?> = _post

private val lifecycleRegistry = LifecycleRegistry(this)
override fun getLifecycle(): Lifecycle = lifecycleRegistry
private val lifecycleOwner = object : LifecycleOwner {
val lifecycleRegistry = LifecycleRegistry(this)
override fun getLifecycle(): Lifecycle {
return lifecycleRegistry
}
}

init {
lifecycleRegistry.markState(Lifecycle.State.CREATED)
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.CREATED
dispatcher.register(this)
}

Expand All @@ -89,7 +93,7 @@ class HistoryViewModel @Inject constructor(
}
isStarted = true
this.site = site
connectionStatus.observe(this, Observer {
connectionStatus.observe(lifecycleOwner, Observer {
if (it == AVAILABLE) {
fetchRevisions()
}
Expand All @@ -106,7 +110,7 @@ class HistoryViewModel @Inject constructor(

fetchRevisions()

lifecycleRegistry.markState(Lifecycle.State.STARTED)
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.STARTED
}
}

Expand Down Expand Up @@ -205,7 +209,7 @@ class HistoryViewModel @Inject constructor(

override fun onCleared() {
dispatcher.unregister(this)
lifecycleRegistry.markState(Lifecycle.State.DESTROYED)
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
super.onCleared()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PostListViewModel @Inject constructor(
@Named(UI_THREAD) private val uiDispatcher: CoroutineDispatcher,
@Named(BG_THREAD) private val bgDispatcher: CoroutineDispatcher,
connectionStatus: LiveData<ConnectionStatus>
) : ScopedViewModel(uiDispatcher), LifecycleOwner {
) : ScopedViewModel(uiDispatcher) {
private val isStatsSupported: Boolean by lazy {
SiteUtils.isAccessedViaWPComRest(connector.site) && connector.site.hasCapabilityViewStats
}
Expand Down Expand Up @@ -119,8 +119,10 @@ class PostListViewModel @Inject constructor(
private var searchProgressJob: Job? = null
private lateinit var authorFilterSelection: AuthorFilterSelection

private val lifecycleRegistry = LifecycleRegistry(this)
override fun getLifecycle(): Lifecycle = lifecycleRegistry
private val lifecycleOwner = object : LifecycleOwner {
val lifecycleRegistry = LifecycleRegistry(this)
override fun getLifecycle(): Lifecycle = lifecycleRegistry
}

fun start(
postListViewModelConnector: PostListViewModelConnector,
Expand All @@ -136,7 +138,7 @@ class PostListViewModel @Inject constructor(
connector = postListViewModelConnector

isStarted = true
lifecycleRegistry.markState(Lifecycle.State.STARTED)
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.STARTED

if (connector.postListType == SEARCH) {
this.authorFilterSelection = EVERYONE
Expand All @@ -146,7 +148,7 @@ class PostListViewModel @Inject constructor(
* We don't want to initialize the list with empty search query in search mode as it'd send an unnecessary
* request to fetch ids of all posts on the site.
*/
initList(dataSource, lifecycle)
initList(dataSource, lifecycleOwner.lifecycle)
}
}

Expand Down Expand Up @@ -261,10 +263,10 @@ class PostListViewModel @Inject constructor(
}

init {
connectionStatus.observe(this, Observer {
connectionStatus.observe(lifecycleOwner, Observer {
retryOnConnectionAvailableAfterRefreshError()
})
lifecycleRegistry.markState(Lifecycle.State.CREATED)
lifecycleOwner.lifecycleRegistry.markState(Lifecycle.State.CREATED)
}

fun search(query: String?, delay: Long = SEARCH_DELAY_MS) {
Expand All @@ -284,7 +286,7 @@ class PostListViewModel @Inject constructor(
delay(delay)
searchJob = null
if (isActive) {
initList(dataSource, lifecycle)
initList(dataSource, lifecycleOwner.lifecycle)
}
}
}
Expand All @@ -304,7 +306,7 @@ class PostListViewModel @Inject constructor(
}

override fun onCleared() {
lifecycleRegistry.markState(Lifecycle.State.DESTROYED)
lifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.DESTROYED
super.onCleared()
}

Expand Down Expand Up @@ -400,7 +402,7 @@ class PostListViewModel @Inject constructor(
fun updateAuthorFilterIfNotSearch(authorFilterSelection: AuthorFilterSelection): Boolean {
if (connector.postListType != SEARCH && this.authorFilterSelection != authorFilterSelection) {
this.authorFilterSelection = authorFilterSelection
initList(dataSource, lifecycle)
initList(dataSource, lifecycleOwner.lifecycle)
return true
}
return false
Expand Down
Loading