upgdate packages and migrate to kotlin 1.4.31

This commit is contained in:
Tlaster 2021-03-01 13:55:17 +08:00
parent e325e886ac
commit 18e42f86a4
37 changed files with 188 additions and 158 deletions

View File

@ -2,13 +2,13 @@
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
@ -20,16 +20,17 @@ allprojects {
projectVersionCode = 515
projectVersionName = '4.1.6'
globalCompileSdkVersion = 29
globalBuildToolsVersion = "29.0.3"
globalCompileSdkVersion = 30
globalBuildToolsVersion = "30.0.3"
globalMinSdkVersion = 16
globalTargetSdkVersion = 29
globalTargetSdkVersion = 30
}
repositories {
mavenLocal()
jcenter()
jcenter()// exoplayer and glide-transformations still using jcenter
mavenCentral()
maven { url "https://jitpack.io" }
google()
}
@ -38,12 +39,12 @@ allprojects {
subprojects {
buildscript {
ext {
kotlinVersion = '1.3.72'
kotlinVersion = '1.4.31'
sharedVersions = [
Kotlin : "${kotlinVersion}",
LoganSquare : '1.3.7',
Jackson : '2.11.1',
Jackson : '2.12.1',
ParcelablePlease : '1.0.2',
ExportablePreferences: '0.9.7',

View File

@ -1,5 +1,6 @@
#Mon Mar 01 10:46:00 CST 2021
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip

View File

@ -38,5 +38,5 @@ android {
}
dependencies {
implementation 'androidx.core:core:1.3.0'
implementation 'androidx.core:core:1.3.2'
}

View File

@ -175,8 +175,8 @@ ext {
libVersions = [
Kovenant : '3.3.0',
Mime4J : '0.7.2',
Dagger : '2.28.1',
Exoplayer : '2.11.7',
Dagger : '2.32',
Exoplayer : '2.13.2',
Glide : '4.11.0',
MediaViewerLibrary: '0.9.23',
Stetho : '1.5.1',
@ -197,20 +197,18 @@ dependencies {
/** Android support **/
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
implementation 'androidx.appcompat:appcompat:1.3.0-beta01'
implementation 'androidx.browser:browser:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.core:core:1.3.0'
implementation 'androidx.core:core-ktx:1.3.0'
implementation 'androidx.drawerlayout:drawerlayout:1.1.0-alpha01'
implementation 'androidx.exifinterface:exifinterface:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.drawerlayout:drawerlayout:1.1.1'
implementation 'androidx.exifinterface:exifinterface:1.3.1'
implementation 'androidx.legacy:legacy-support-core-ui:1.0.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.palette:palette-ktx:1.0.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.3.0'
/** Third-party dependencies **/
@ -236,7 +234,7 @@ dependencies {
implementation "com.hannesdorfmann.parcelableplease:annotation:${sharedVersions['ParcelablePlease']}"
kapt "com.hannesdorfmann.parcelableplease:processor:${sharedVersions['ParcelablePlease']}"
implementation 'com.squareup.okhttp3:okhttp:3.12.12'
implementation 'com.squareup.okio:okio:2.6.0'
implementation 'com.squareup.okio:okio:2.9.0'
implementation 'com.lnikkila:extendedtouchview:0.1.1'
implementation "com.google.dagger:dagger:${libVersions['Dagger']}"
kapt "com.google.dagger:dagger-compiler:${libVersions['Dagger']}"
@ -244,8 +242,8 @@ dependencies {
implementation 'com.getkeepsafe.taptargetview:taptargetview:1.13.0'
implementation 'net.ypresto.androidtranscoder:android-transcoder:0.3.0'
implementation 'org.jsoup:jsoup:1.13.1'
implementation "com.google.android.exoplayer:exoplayer-core:${libVersions['Exoplayer']}"
implementation "com.google.android.exoplayer:exoplayer-ui:${libVersions['Exoplayer']}"
implementation "com.google.android.exoplayer:exoplayer:${libVersions['Exoplayer']}"
// implementation "com.google.android.exoplayer:exoplayer-ui:${libVersions['Exoplayer']}"
implementation "com.google.android.exoplayer:extension-okhttp:${libVersions['Exoplayer']}"
implementation "com.github.bumptech.glide:glide:${libVersions['Glide']}"
implementation "com.github.bumptech.glide:okhttp3-integration:${libVersions['Glide']}@aar"
@ -287,7 +285,8 @@ dependencies {
/** Flavor dependencies **/
fdroidImplementation 'org.osmdroid:osmdroid-android:5.6.5'
fdroidImplementation 'ch.acra:acra:4.11'
fdroidImplementation 'ch.acra:acra-mail:5.7.0'
fdroidImplementation 'ch.acra:acra-dialog:5.7.0'
if (enableGoogleVariant) {
// START Non-FOSS component
@ -308,7 +307,7 @@ dependencies {
debugImplementation "com.facebook.stetho:stetho:${libVersions['Stetho']}"
debugImplementation "com.facebook.stetho:stetho-okhttp3:${libVersions['Stetho']}"
debugImplementation 'com.github.mariotaku:StethoBeanShellREPL:0.5'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.6'
debugImplementation('com.jayway.jsonpath:json-path:2.4.0') {
exclude group: 'net.minidev', module: 'json-smart'
}
@ -317,10 +316,10 @@ dependencies {
/** Testing **/
testImplementation 'junit:junit:4.13'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test:rules:1.3.0'
// https://g.co/androidstudio/app-test-app-conflict
androidTestImplementation 'com.google.code.findbugs:jsr305:3.0.2'
}

View File

@ -38,15 +38,4 @@ class CrashReportDialogActivity : CrashReportDialog() {
view.setPadding(padding, padding, padding, padding)
return view
}
override fun getMainView(): View {
val text = TextView(this)
TextViewCompat.setTextAppearance(text, android.R.style.TextAppearance_DeviceDefault_Medium)
val dialogTextId = this.config.resDialogText()
if (dialogTextId != 0) {
text.text = this.getText(dialogTextId)
}
return text
}
}

View File

@ -27,8 +27,10 @@ import android.app.Application
import android.content.SharedPreferences
import android.os.Build
import org.acra.ACRA
import org.acra.ReportingInteractionMode
import org.acra.config.ConfigurationBuilder
import org.acra.config.CoreConfigurationBuilder
import org.acra.config.DialogConfigurationBuilder
import org.acra.config.MailSenderConfigurationBuilder
import org.acra.data.StringFormat
import org.mariotaku.kpreferences.get
import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe
import org.mariotaku.twidere.BuildConfig
@ -40,6 +42,7 @@ import org.mariotaku.twidere.constant.themeBackgroundAlphaKey
import org.mariotaku.twidere.constant.themeBackgroundOptionKey
import org.mariotaku.twidere.constant.themeKey
/**
* Created by mariotaku on 2017/5/8.
*/
@ -56,14 +59,17 @@ class ACRAAnalyzer : Analyzer() {
}
override fun init(application: Application) {
val config = ConfigurationBuilder(application)
.setReportingInteractionMode(ReportingInteractionMode.DIALOG)
.setResDialogText(R.string.message_app_crashed)
.setResDialogTheme(R.style.Theme_Twidere_NoDisplay_DayNight)
val builder = CoreConfigurationBuilder(application)
builder.setBuildConfigClass(BuildConfig::class.java).setReportFormat(StringFormat.JSON)
builder.getPluginConfigurationBuilder(DialogConfigurationBuilder::class.java)
.setResText(R.string.message_app_crashed)
.setResTheme(R.style.Theme_Twidere_NoDisplay_DayNight)
.setReportDialogClass(CrashReportDialogActivity::class.java)
.setEnabled(true)
builder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder::class.java)
.setMailTo(TWIDERE_PROJECT_EMAIL)
.build()
ACRA.init(application, config)
.setEnabled(true)
ACRA.init(application, builder)
val reporter = ACRA.getErrorReporter()
reporter.putCustomData("debug", BuildConfig.DEBUG.toString())
reporter.putCustomData("build.brand", Build.BRAND)

View File

@ -23,7 +23,7 @@ import android.content.Intent
import android.os.Parcelable
inline fun <reified T : Parcelable> Intent.getTypedArrayExtra(key: String): Array<T> {
val extra = getParcelableArrayExtra(key)
val extra = getParcelableArrayExtra(key) ?: emptyArray()
return Array(extra.size) { extra[it] as T }
}

View File

@ -196,9 +196,10 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
private set
override fun getSystemWindowInsets(caller: Fragment, insets: Rect): Boolean {
if (systemWindowsInsets == null) return false
insets.set(systemWindowsInsets)
return true
return systemWindowsInsets?.let {
insets.set(it)
true
} ?: false
}
override fun onApplyWindowInsets(v: View, insets: WindowInsetsCompat): WindowInsetsCompat {

View File

@ -70,7 +70,7 @@ class BrowserSignInActivity : BaseActivity() {
setSupportMultipleWindows(true)
}
webView.loadUrl(intent.dataString)
intent.dataString?.let { webView.loadUrl(it) }
}
override fun onDestroy() {

View File

@ -124,6 +124,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
// Utility classes
@Inject
lateinit var extractor: Extractor
@Inject
lateinit var locationManager: LocationManager
@ -362,7 +363,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
statusShortenerUsed = !ComponentPickerPreference.isNoneValue(kPreferences[statusShortenerKey])
if (kPreferences[attachLocationKey]) {
if (checkAnySelfPermissionsGranted(AndroidPermission.ACCESS_COARSE_LOCATION,
AndroidPermission.ACCESS_FINE_LOCATION)) {
AndroidPermission.ACCESS_FINE_LOCATION)) {
try {
startLocationUpdateIfEnabled()
} catch (e: SecurityException) {
@ -379,8 +380,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
saveAccountSelection()
saveVisibility()
try {
if (locationListener != null) {
locationManager.removeUpdates(locationListener)
locationListener?.let {
locationManager.removeUpdates(it)
locationListener = null
}
} catch (ignore: SecurityException) {
@ -397,8 +398,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
if (resultCode == Activity.RESULT_OK && data != null) {
val src = MediaPickerActivity.getMediaUris(data)
TaskStarter.execute(AddMediaTask(this, src, null,
copySrc = false,
deleteSrc = false
copySrc = false,
deleteSrc = false
))
val extras = data.getBundleExtra(MediaPickerActivity.EXTRA_EXTRAS)
if (extras?.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE) == true) {
@ -417,9 +418,9 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
REQUEST_EXTENSION_COMPOSE -> {
if (resultCode == Activity.RESULT_OK && data != null) {
// The latter two is for compatibility
val text = data.getCharSequenceExtra(Intent.EXTRA_TEXT) ?:
data.getStringExtra(EXTRA_TEXT) ?:
data.getStringExtra(EXTRA_APPEND_TEXT)
val text = data.getCharSequenceExtra(Intent.EXTRA_TEXT)
?: data.getStringExtra(EXTRA_TEXT)
?: data.getStringExtra(EXTRA_APPEND_TEXT)
val isReplaceMode = data.getBooleanExtra(EXTRA_IS_REPLACE_MODE,
data.getStringExtra(EXTRA_APPEND_TEXT) == null)
if (text != null) {
@ -433,12 +434,12 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
updateTextCount()
}
val src = MediaPickerActivity.getMediaUris(data)?.takeIf(Array<Uri>::isNotEmpty) ?:
data.getParcelableExtra<Uri>(EXTRA_IMAGE_URI)?.let { arrayOf(it) }
val src = MediaPickerActivity.getMediaUris(data)?.takeIf(Array<Uri>::isNotEmpty)
?: data.getParcelableExtra<Uri>(EXTRA_IMAGE_URI)?.let { arrayOf(it) }
if (src != null) {
TaskStarter.execute(AddMediaTask(this, src, null,
copySrc = false,
deleteSrc = false
copySrc = false,
deleteSrc = false
))
}
}
@ -618,7 +619,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
when (ev.actionMasked) {
MotionEvent.ACTION_DOWN -> {
if (isAccountSelectorVisible && !TwidereViewUtils.hitView(ev, accountSelectorButton)) {
val layoutManager = accountSelector.layoutManager ?: return super.dispatchTouchEvent(ev)
val layoutManager = accountSelector.layoutManager
?: return super.dispatchTouchEvent(ev)
val clickedItem = (0 until layoutManager.childCount).any {
val child = layoutManager.getChildAt(it)
child != null && TwidereViewUtils.hitView(ev, child)
@ -786,8 +788,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
requestOrUpdateLocation()
} else if (locationListener != null) {
try {
locationManager.removeUpdates(locationListener)
locationListener = null
locationListener?.let {
locationManager.removeUpdates(it)
locationListener = null
}
} catch (e: SecurityException) {
//Ignore
}
@ -1090,20 +1094,20 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
if (intent == null) return false
val action = intent.action
val hasVisibility = intent.hasExtra(EXTRA_VISIBILITY)
val hasAccountKeys: Boolean
when {
val hasAccountKeys: Boolean = when {
intent.hasExtra(EXTRA_ACCOUNT_KEYS) -> {
val accountKeys = intent.getTypedArrayExtra<UserKey>(EXTRA_ACCOUNT_KEYS)
accountsAdapter.selectedAccountKeys = accountKeys
hasAccountKeys = true
true
}
intent.hasExtra(EXTRA_ACCOUNT_KEY) -> {
val accountKey = intent.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY)
accountsAdapter.selectedAccountKeys = arrayOf(accountKey)
hasAccountKeys = true
intent.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY)?.let {
accountsAdapter.selectedAccountKeys = arrayOf(it)
true
} ?: false
}
else -> {
hasAccountKeys = false
false
}
}
when (action) {
@ -1114,8 +1118,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
if (stream != null) {
val src = stream.toTypedArray()
TaskStarter.execute(AddMediaTask(this, src, null,
copySrc = true,
deleteSrc = false
copySrc = true,
deleteSrc = false
))
}
}
@ -1126,8 +1130,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
if (data != null) {
val src = arrayOf(data)
TaskStarter.execute(AddMediaTask(this, src, null,
copySrc = true,
deleteSrc = false
copySrc = true,
deleteSrc = false
))
}
}
@ -1246,7 +1250,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
}
private fun handleReplyMultipleIntent(screenNames: Array<String>?, accountKey: UserKey?,
inReplyToStatus: ParcelableStatus?): Boolean {
inReplyToStatus: ParcelableStatus?): Boolean {
if (screenNames == null || screenNames.isEmpty() || accountKey == null ||
inReplyToStatus == null) return false
val myScreenName = DataStoreUtils.getAccountScreenName(this, accountKey) ?: return false
@ -1444,8 +1448,9 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
val provider = locationManager.getBestProvider(criteria, true)
if (provider != null) {
locationLabel.setText(R.string.getting_location)
locationListener = ComposeLocationListener(this)
locationManager.requestLocationUpdates(provider, 0, 0f, locationListener)
locationListener = ComposeLocationListener(this).also {
locationManager.requestLocationUpdates(provider, 0, 0f, it)
}
val location = locationManager.getCachedLocation()
if (location != null) {
locationListener?.onLocationChanged(location)
@ -1716,7 +1721,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
}
private fun getTwitterReplyTextAndMentions(text: String = editText.text?.toString().orEmpty(),
accounts: Array<AccountDetails> = accountsAdapter.selectedAccounts): ReplyTextAndMentions? {
accounts: Array<AccountDetails> = accountsAdapter.selectedAccounts): ReplyTextAndMentions? {
val inReplyTo = inReplyToStatus ?: return null
if (!ignoreMentions) return null
val account = accounts.singleOrNull() ?: return null
@ -1841,8 +1846,8 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
editText.customSelectionActionModeCallback = this
editText.imageInputListener = { contentInfo ->
val task = AddMediaTask(this, arrayOf(contentInfo.contentUri), null,
copySrc = true,
deleteSrc = false
copySrc = true,
deleteSrc = false
)
task.callback = {
contentInfo.releasePermission()
@ -2083,11 +2088,11 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
}
private class AddMediaTask(activity: ComposeActivity, sources: Array<Uri>, types: IntArray?,
copySrc: Boolean, deleteSrc: Boolean) : AbsAddMediaTask<((List<ParcelableMediaUpdate>?) -> Unit)?>(
copySrc: Boolean, deleteSrc: Boolean) : AbsAddMediaTask<((List<ParcelableMediaUpdate>?) -> Unit)?>(
activity, sources, types, copySrc, deleteSrc) {
override fun afterExecute(callback: ((List<ParcelableMediaUpdate>?) -> Unit)?,
result: List<ParcelableMediaUpdate>?) {
result: List<ParcelableMediaUpdate>?) {
callback?.invoke(result)
val activity = context as? ComposeActivity ?: return
activity.setProgressVisible(false)

View File

@ -11,11 +11,14 @@ class FragmentContentActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
title = intent.getStringExtra(EXTRA_TITLE)
val fragment = Fragment.instantiate(this, intent.getStringExtra(EXTRA_FRAGMENT),
intent.getStringExtra(EXTRA_FRAGMENT)?.let {
Fragment.instantiate(this, it,
intent.getBundleExtra(EXTRA_FRAGMENT_ARGUMENTS))
val ft = supportFragmentManager.beginTransaction()
ft.replace(android.R.id.content, fragment)
ft.commit()
}?.let { fragment ->
val ft = supportFragmentManager.beginTransaction()
ft.replace(android.R.id.content, fragment)
ft.commit()
}
}
companion object {

View File

@ -732,7 +732,9 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
} else {
Utils.getDefaultAccountKey(this)
}
IntentUtils.openSearch(this, accountKey, query)
if (query != null) {
IntentUtils.openSearch(this, accountKey, query)
}
return -1
}
val refreshOnStart = preferences.getBoolean(SharedPreferenceConstants.KEY_REFRESH_ON_START, false)

View File

@ -41,18 +41,18 @@ class ImageCropperActivity : BaseActivity(), CropImageView.OnSetImageUriComplete
/**
* Persist URI image to crop URI if specific permissions are required
*/
private val cropImageUri: Uri get() = intent.getParcelableExtra(CropImage.CROP_IMAGE_EXTRA_SOURCE)
private val cropImageUri: Uri? get() = intent.getParcelableExtra(CropImage.CROP_IMAGE_EXTRA_SOURCE)
/**
* the options that were set for the crop image
*/
private val options: CropImageOptions get() = intent.getParcelableExtra(CropImage.CROP_IMAGE_EXTRA_OPTIONS)
private val options: CropImageOptions? get() = intent.getParcelableExtra(CropImage.CROP_IMAGE_EXTRA_OPTIONS)
/**
* Get Android uri to save the cropped image into.<br></br>
* Use the given in options or create a temp file.
*/
private val outputUri: Uri get() = options.outputUri
private val outputUri: Uri? get() = options?.outputUri
@SuppressLint("NewApi")
public override fun onCreate(savedInstanceState: Bundle?) {
@ -107,11 +107,13 @@ class ImageCropperActivity : BaseActivity(), CropImageView.OnSetImageUriComplete
override fun onSetImageUriComplete(view: CropImageView, uri: Uri, error: Exception?) {
if (error == null) {
if (options.initialCropWindowRectangle != null) {
cropImageView.cropRect = options.initialCropWindowRectangle
}
if (options.initialRotation > -1) {
cropImageView.rotatedDegrees = options.initialRotation
options?.let { options ->
if (options.initialCropWindowRectangle != null) {
cropImageView.cropRect = options.initialCropWindowRectangle
}
if (options.initialRotation > -1) {
cropImageView.rotatedDegrees = options.initialRotation
}
}
} else {
setResult(null, error, 1)
@ -128,16 +130,18 @@ class ImageCropperActivity : BaseActivity(), CropImageView.OnSetImageUriComplete
* Execute crop image and save the result to output uri.
*/
private fun cropImage() {
if (options.noOutputImage) {
setResult(null, null, 1)
} else {
val outputUri = outputUri
cropImageView.saveCroppedImageAsync(outputUri,
options.outputCompressFormat,
options.outputCompressQuality,
options.outputRequestWidth,
options.outputRequestHeight,
options.outputRequestSizeOptions)
options?.let { options ->
if (options.noOutputImage) {
setResult(null, null, 1)
} else {
val outputUri = outputUri
cropImageView.saveCroppedImageAsync(outputUri,
options.outputCompressFormat,
options.outputCompressQuality,
options.outputRequestWidth,
options.outputRequestHeight,
options.outputRequestSizeOptions)
}
}
}

View File

@ -111,7 +111,7 @@ class KeyboardShortcutPreferenceCompatActivity : BaseActivity(), OnClickListener
return true
}
private val contextTag: String
private val contextTag: String?
get() = intent.getStringExtra(EXTRA_CONTEXT_TAG)
private val keyAction: String?

View File

@ -174,7 +174,9 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher,
when (requestCode) {
REQUEST_EDIT_API -> {
if (resultCode == Activity.RESULT_OK && data != null) {
apiConfig = data.getParcelableExtra(EXTRA_API_CONFIG)
data.getParcelableExtra<CustomAPIConfig>(EXTRA_API_CONFIG)?.let {
apiConfig = it
}
updateSignInType()
}
setSignInButton()
@ -193,7 +195,9 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher,
val clientId = extras.getString(EXTRA_CLIENT_ID)!!
val clientSecret = extras.getString(EXTRA_CLIENT_SECRET)!!
finishMastodonBrowserLogin(host, clientId, clientSecret, code)
if (code != null) {
finishMastodonBrowserLogin(host, clientId, clientSecret, code)
}
}
}
}

View File

@ -137,7 +137,7 @@ class UserListSelectorActivity : BaseActivity(),
when (requestCode) {
REQUEST_SELECT_USER -> {
if (resultCode == Activity.RESULT_OK && data != null) {
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER)
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER) ?: return
loadUserLists(accountKey!!, user.key)
}
}

View File

@ -74,7 +74,9 @@ abstract class AbsStatusDialogActivity : BaseActivity() {
return
}
val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY)
showDialogFragment(accountKey, statusId, status)
if (accountKey != null) {
showDialogFragment(accountKey, statusId, status)
}
return
}
}

View File

@ -11,7 +11,7 @@ import org.mariotaku.twidere.model.premium.PurchaseResult
*/
abstract class AbsExtraFeaturePurchaseActivity : BaseActivity() {
protected val requestingFeature: String get() = intent.getStringExtra(EXTRA_REQUESTING_FEATURE)
protected val requestingFeature: String? get() = intent.getStringExtra(EXTRA_REQUESTING_FEATURE)
protected fun finishWithError(code: Int) {
setResult(code)

View File

@ -44,8 +44,10 @@ abstract class AbsUserListRelatedShortcutCreatorActivity : AbsShortcutCreatorAct
}
val list = data.getParcelableExtra<ParcelableUserList>(EXTRA_USER_LIST)
val extras = data.getBundleExtra(EXTRA_EXTRAS)
val accountKey = extras.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
onUserListSelected(accountKey, list)
val accountKey = extras?.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
if (list != null) {
onUserListSelected(accountKey, list)
}
}
else -> {
super.onActivityResult(requestCode, resultCode, data)

View File

@ -44,8 +44,10 @@ abstract class AbsUserRelatedShortcutCreatorActivity : AbsShortcutCreatorActivit
}
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER)
val extras = data.getBundleExtra(EXTRA_EXTRAS)
val accountKey = extras.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
onUserSelected(accountKey, user)
val accountKey = extras?.getParcelable<UserKey>(EXTRA_ACCOUNT_KEY)
if (user != null) {
onUserSelected(accountKey, user)
}
}
else -> {
super.onActivityResult(requestCode, resultCode, data)

View File

@ -176,7 +176,7 @@ class TwidereApplication : Application(), OnSharedPreferenceChangeListener {
}, updateImmediately = true)
}
override fun onConfigurationChanged(newConfig: Configuration?) {
override fun onConfigurationChanged(newConfig: Configuration) {
applyLanguageSettings()
super.onConfigurationChanged(newConfig)
}

View File

@ -32,7 +32,7 @@ val ConnectivityManager.activateNetworkCompat: Network?
return activeNetwork
}
val activeInfo = activeNetworkInfo ?: return null
return allNetworks.firstOrNull { activeInfo.same(getNetworkInfo(it)) }
return allNetworks.firstOrNull { getNetworkInfo(it)?.let { it1 -> activeInfo.same(it1) } == true }
}
private fun NetworkInfo.same(another: NetworkInfo) = type == another.type && subtype == another.subtype

View File

@ -95,7 +95,7 @@ class AccountsManagerFragment : BaseFragment(), LoaderManager.LoaderCallbacks<Li
if (resultCode != Activity.RESULT_OK || data == null)
return
val am = AccountManager.get(context)
val accountKey: UserKey = data.getBundleExtra(EXTRA_EXTRAS).getParcelable(EXTRA_ACCOUNT_KEY) ?: return
val accountKey: UserKey = data.getBundleExtra(EXTRA_EXTRAS)?.getParcelable(EXTRA_ACCOUNT_KEY) ?: return
val color = data.getIntExtra(EXTRA_COLOR, Color.WHITE)
val details = adapter.findItem(accountKey) ?: return
details.color = color

View File

@ -57,7 +57,7 @@ open class BaseWebViewFragment : BaseFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
internalWebView?.destroy()
internalWebView = WebView(activity)
internalWebView = activity?.let { WebView(it) }
webViewAvailable = true
return internalWebView
}

View File

@ -113,7 +113,7 @@ class UserListFragment : AbsToolbarTabPagesFragment(), OnClickListener,
val userList = this.userList
if (resultCode != Activity.RESULT_OK || !data!!.hasExtra(EXTRA_USER) || userList == null)
return
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER)
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER) ?: return
twitter.addUserListMembersAsync(userList.account_key, userList.id, user)
return
}

View File

@ -64,7 +64,7 @@ class FilteredUsersFragment : BaseFiltersFragment() {
when (requestCode) {
REQUEST_SELECT_USER -> {
if (resultCode != FragmentActivity.RESULT_OK || data == null) return
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER)
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER) ?: return
executeAfterFragmentResumed { fragment ->
AddUserFilterDialogFragment.show(fragment.childFragmentManager, user)
}
@ -92,7 +92,7 @@ class FilteredUsersFragment : BaseFiltersFragment() {
}
REQUEST_EXPORT_MUTES_SELECT_ACCOUNT -> {
if (resultCode != FragmentActivity.RESULT_OK || data == null) return
val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY)
val accountKey = data.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY) ?: return
val userKeys = data.getBundleExtra(EXTRA_EXTRAS)?.getNullableTypedArray<UserKey>(EXTRA_ITEMS) ?: return
exportToMutedUsers(accountKey, userKeys)
}

View File

@ -45,7 +45,10 @@ class ExternalBrowserPageFragment : MediaViewerFragment() {
webSettings.javaScriptEnabled = true
webSettings.loadsImagesAutomatically = true
val media = arguments?.getParcelable<ParcelableMedia>(EXTRA_MEDIA) ?: throw NullPointerException()
webView.loadUrl(if (TextUtils.isEmpty(media.media_url)) media.url else media.media_url)
val target = if (TextUtils.isEmpty(media.media_url)) media.url else media.media_url
target?.let {
webView.loadUrl(it)
}
webViewContainer.setAspectRatioSource(VideoPageFragment.MediaAspectRatioSource(media, this))
}

View File

@ -188,8 +188,9 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
when (requestCode) {
REQUEST_CONVERSATION_ADD_USER -> {
if (resultCode == Activity.RESULT_OK && data != null) {
val user = data.getParcelableExtra<ParcelableUser>(EXTRA_USER)
performAddParticipant(user)
data.getParcelableExtra<ParcelableUser>(EXTRA_USER)?.let { user ->
performAddParticipant(user)
}
}
}
REQUEST_PICK_MEDIA -> {
@ -299,7 +300,7 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
ProgressDialogFragment.show(childFragmentManager, "leave_conversation_progress")
val weakThis = WeakReference(this)
val task = DestroyConversationTask(requireContext(), accountKey, conversationId)
task.callback = callback@ { succeed ->
task.callback = callback@{ succeed ->
val f = weakThis.get() ?: return@callback
f.dismissDialogThen("leave_conversation_progress") {
if (succeed) {
@ -315,7 +316,7 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
ProgressDialogFragment.show(childFragmentManager, "clear_messages_progress")
val weakThis = WeakReference(this)
val task = ClearMessagesTask(requireContext(), accountKey, conversationId)
task.callback = callback@ { succeed ->
task.callback = callback@{ succeed ->
val f = weakThis.get() ?: return@callback
f.dismissDialogThen("clear_messages_progress") {
if (succeed) {
@ -343,7 +344,7 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
ProgressDialogFragment.show(childFragmentManager, "set_notifications_disabled_progress")
val weakThis = WeakReference(this)
val task = SetConversationNotificationDisabledTask(requireContext(), accountKey, conversationId, disabled)
task.callback = callback@ { _ ->
task.callback = callback@{ _ ->
val f = weakThis.get() ?: return@callback
f.dismissDialogThen("set_notifications_disabled_progress") {
LoaderManager.getInstance(this).restartLoader(0, null, this)
@ -378,7 +379,7 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
private fun performSetConversationName(name: String) {
val conversationId = this.conversationId
performUpdateInfo("set_name_progress", updateAction = updateAction@ { fragment, account, microBlog ->
performUpdateInfo("set_name_progress", updateAction = updateAction@{ fragment, account, microBlog ->
val context = fragment.context
when (account.type) {
AccountType.TWITTER -> {
@ -395,7 +396,7 @@ class MessageConversationInfoFragment : BaseFragment(), IToolBarSupportFragment,
private fun performSetConversationAvatar(uri: Uri?) {
val conversationId = this.conversationId
performUpdateInfo("set_avatar_progress", updateAction = updateAction@ { fragment, account, microBlog ->
performUpdateInfo("set_avatar_progress", updateAction = updateAction@{ fragment, account, microBlog ->
val context = fragment.context
when (account.type) {
AccountType.TWITTER -> {

View File

@ -105,7 +105,7 @@ class MessagesEntriesFragment : AbsContentListRecyclerViewFragment<MessagesEntri
when (requestCode) {
REQUEST_SELECT_ACCOUNT -> {
if (resultCode != Activity.RESULT_OK) return
val accountKey = data!!.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY)
val accountKey = data?.getParcelableExtra<UserKey>(EXTRA_ACCOUNT_KEY) ?: return
startActivity(IntentUtils.newMessageConversation(accountKey))
}
else -> {

View File

@ -38,9 +38,10 @@ class AccountActionProvider(
for (i in 0 until subMenu.size()) {
val item = subMenu.getItem(i)
val intent = item.intent
val account: AccountDetails = intent.getParcelableExtra(EXTRA_ACCOUNT)
if (it.contains(account.key)) {
item.isChecked = true
intent.getParcelableExtra<AccountDetails>(EXTRA_ACCOUNT)?.let { account ->
if (it.contains(account.key)) {
item.isChecked = true
}
}
}
}

View File

@ -19,7 +19,7 @@ data class PurchaseFinished(val productName: String) : Analyzer.Event {
const val NAME_EXTRA_FEATURES = "Enhanced Features"
fun create(data: Intent): PurchaseFinished {
val purchaseResult: PurchaseResult = data.getParcelableExtra(EXTRA_PURCHASE_RESULT)
val purchaseResult: PurchaseResult = data.getParcelableExtra(EXTRA_PURCHASE_RESULT)!!
val result = PurchaseFinished(purchaseResult.feature)
result.price = purchaseResult.price
result.currency = purchaseResult.currency

View File

@ -65,8 +65,9 @@ open class TrendsLocationExtraConfiguration(
when (requestCode) {
1 -> {
if (resultCode == Activity.RESULT_OK && data != null) {
val location = data.getParcelableExtra<Location>(EXTRA_LOCATION)
value = Place(location.woeid, location.name)
data.getParcelableExtra<Location>(EXTRA_LOCATION)?.let { location ->
value = Place(location.woeid, location.name)
}
}
}
}

View File

@ -62,11 +62,12 @@ class UserExtraConfiguration(key: String) : TabConfiguration.ExtraConfiguration(
when (requestCode) {
1 -> {
if (resultCode == Activity.RESULT_OK && data != null) {
val user: ParcelableUser = data.getParcelableExtra(EXTRA_USER)
viewHolder.displayUser(user)
viewHolder.itemView.visibility = View.VISIBLE
hintView.visibility = View.GONE
this.value = user
data.getParcelableExtra<ParcelableUser>(EXTRA_USER)?.let { user ->
viewHolder.displayUser(user)
viewHolder.itemView.visibility = View.VISIBLE
hintView.visibility = View.GONE
this.value = user
}
}
}
}

View File

@ -63,12 +63,13 @@ class UserListExtraConfiguration(key: String) : TabConfiguration.ExtraConfigurat
when (requestCode) {
1 -> {
if (resultCode == Activity.RESULT_OK) {
val userList: ParcelableUserList = data!!.getParcelableExtra(EXTRA_USER_LIST)
viewHolder.display(userList)
viewHolder.itemView.visibility = View.VISIBLE
hintView.visibility = View.GONE
data?.getParcelableExtra<ParcelableUserList>(EXTRA_USER_LIST)?.let { userList ->
viewHolder.display(userList)
viewHolder.itemView.visibility = View.VISIBLE
hintView.visibility = View.GONE
this.value = userList
this.value = userList
}
}
}
}

View File

@ -158,7 +158,7 @@ class MultiSelectEventHandler(
if (item.groupId == AccountActionProvider.MENU_GROUP) {
val intent = item.intent
if (intent == null || !intent.hasExtra(EXTRA_ACCOUNT)) return false
val account: AccountDetails = intent.getParcelableExtra(EXTRA_ACCOUNT)
val account: AccountDetails = intent.getParcelableExtra(EXTRA_ACCOUNT) ?: return false
multiSelectManager.accountKey = account.key
accountActionProvider?.selectedAccountKeys = arrayOf(account.key)
mode.invalidate()

View File

@ -14,12 +14,13 @@ private fun Context.fixForLollipop(): Context {
class LollipopFixWebView: WebView {
constructor(context: Context?) : super(context?.fixForLollipop())
constructor(context: Context?, attrs: AttributeSet?) : super(context?.fixForLollipop(), attrs)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context?.fixForLollipop(), attrs, defStyleAttr)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context?.fixForLollipop(), attrs, defStyleAttr, defStyleRes)
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, privateBrowsing: Boolean) : super(context?.fixForLollipop(), attrs, defStyleAttr, privateBrowsing)
constructor(context: Context) : super(context.fixForLollipop())
constructor(context: Context, attrs: AttributeSet?) : super(context.fixForLollipop(), attrs)
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
context.fixForLollipop(),
attrs,
defStyleAttr
)
init {
isFocusable = true

View File

@ -25,7 +25,7 @@
android:layout_height="match_parent"
android:layout_centerInParent="true">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="match_parent"