Fold some if-thens

This commit is contained in:
TacoTheDank 2020-06-08 19:09:31 -04:00
parent 421147b465
commit 1ac1c58824
19 changed files with 32 additions and 75 deletions

View File

@ -466,8 +466,7 @@ class MediaViewerActivity : BaseActivity(), IMediaViewerActivity, MediaSwipeClos
if (checkAllSelfPermissionsGranted(AndroidPermissions.WRITE_EXTERNAL_STORAGE)) {
saveToStorage()
} else {
val permissions: Array<String>
permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
val permissions: Array<String> = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
arrayOf(AndroidPermissions.WRITE_EXTERNAL_STORAGE, AndroidPermissions.READ_EXTERNAL_STORAGE)
} else {
arrayOf(AndroidPermissions.WRITE_EXTERNAL_STORAGE)

View File

@ -177,23 +177,14 @@ class TrendsLocationSelectorActivity : BaseActivity() {
}
override fun getGroupView(groupPosition: Int, isExpanded: Boolean, convertView: View?, parent: ViewGroup): View {
val view: View
view = if (convertView != null) {
convertView
} else {
inflater.inflate(android.R.layout.simple_expandable_list_item_1, parent, false)
}
val view: View = convertView ?: inflater.inflate(android.R.layout.simple_expandable_list_item_1, parent, false)
view.findViewById<TextView>(android.R.id.text1).text = getGroup(groupPosition).name
return view
}
override fun getChildView(groupPosition: Int, childPosition: Int, isLastChild: Boolean, convertView: View?, parent: ViewGroup): View {
val view: View
view = if (convertView != null) {
convertView
} else {
inflater.inflate(android.R.layout.simple_list_item_1, parent, false)
}
val view: View =
convertView ?: inflater.inflate(android.R.layout.simple_list_item_1, parent, false)
val location = getChild(groupPosition, childPosition)
val text1 = view.findViewById<TextView>(android.R.id.text1)
if (location.parentId == WORLDWIDE) {

View File

@ -36,11 +36,7 @@ class SimpleParcelableUsersAdapter(
override fun getItemId(position: Int): Long {
val item = getItem(position)
return if (item != null) {
item.hashCode().toLong()
} else {
-1
}
return item?.hashCode()?.toLong() ?: -1
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {

View File

@ -63,9 +63,8 @@ fun Credentials.getAuthorization(cls: Class<*>?): Authorization {
}
fun Credentials.getEndpoint(cls: Class<*>): Endpoint {
val apiUrlFormat: String
val noVersionSuffix = this.no_version_suffix
apiUrlFormat = if (!TextUtils.isEmpty(this.api_url_format)) {
val apiUrlFormat: String = if (!TextUtils.isEmpty(this.api_url_format)) {
this.api_url_format
} else {
DEFAULT_TWITTER_API_URL_FORMAT
@ -113,8 +112,7 @@ fun Credentials.getEndpoint(cls: Class<*>): Endpoint {
}
val endpointUrl = MicroBlogAPIFactory.getApiUrl(apiUrlFormat, domain, versionSuffix)
if (this is OAuthCredentials) {
val signEndpointUrl: String
signEndpointUrl = if (same_oauth_signing_url) {
val signEndpointUrl: String = if (same_oauth_signing_url) {
endpointUrl
} else {
MicroBlogAPIFactory.getApiUrl(DEFAULT_TWITTER_API_URL_FORMAT, domain, versionSuffix)

View File

@ -61,11 +61,8 @@ class ColorPickerDialogFragment : BaseDialogFragment(), DialogInterface.OnClickL
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val color: Int
val args = arguments
color = if (savedInstanceState != null) {
savedInstanceState.getInt(EXTRA_COLOR, Color.WHITE)
} else {
args!!.getInt(EXTRA_COLOR, Color.WHITE)
}
color =
savedInstanceState?.getInt(EXTRA_COLOR, Color.WHITE) ?: args!!.getInt(EXTRA_COLOR, Color.WHITE)
val activity = activity
val builder = AlertDialog.Builder(requireActivity())

View File

@ -86,8 +86,7 @@ class TrendsSuggestionsFragment : AbsContentListViewFragment<TrendsAdapter>(), L
override fun onItemClick(view: AdapterView<*>, child: View, position: Int, id: Long) {
if (multiSelectManager.isActive) return
val trend: String?
trend = if (view is ListView) {
val trend: String? = if (view is ListView) {
adapter.getItem(position - view.headerViewsCount)
} else {
adapter.getItem(position)

View File

@ -44,11 +44,7 @@ class AccountPreferences(
val defaultNotificationLightColor: Int
get() {
val a = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true)
return if (a != null) {
a.color
} else {
ContextCompat.getColor(context, R.color.branding_color)
}
return a?.color ?: ContextCompat.getColor(context, R.color.branding_color)
}
val directMessagesNotificationType: Int

View File

@ -167,8 +167,7 @@ class CacheProvider : ContentProvider() {
* Copied from ContentResolver.java
*/
private fun modeToMode(mode: String): Int {
val modeBits: Int
modeBits = if ("r" == mode) {
val modeBits: Int = if ("r" == mode) {
ParcelFileDescriptor.MODE_READ_ONLY
} else if ("w" == mode || "wt" == mode) {
ParcelFileDescriptor.MODE_WRITE_ONLY or ParcelFileDescriptor.MODE_CREATE or ParcelFileDescriptor.MODE_TRUNCATE

View File

@ -216,12 +216,10 @@ class LengthyOperationsService : BaseIntentService("lengthy_operations") {
private fun handleUpdateStatusIntent(intent: Intent) {
val status = intent.getParcelableExtra<ParcelableStatusUpdate>(EXTRA_STATUS)
val statusParcelables = intent.getNullableTypedArrayExtra<ParcelableStatusUpdate>(EXTRA_STATUSES)
val scheduleInfo = intent.getParcelableExtra<ScheduleInfo>(EXTRA_SCHEDULE_INFO)
val statuses: Array<ParcelableStatusUpdate>
statuses = if (statusParcelables != null) {
statusParcelables
} else if (status != null) {
statuses = intent.getNullableTypedArrayExtra(EXTRA_STATUSES)
?: if (status != null) {
arrayOf(status)
} else
return

View File

@ -228,8 +228,7 @@ abstract class GetStatusesTask(
fun getPositionKey(timestamp: Long, sortId: Long, lastSortId: Long, sortDiff: Long,
position: Int, count: Int): Long {
if (sortDiff == 0L) return timestamp
val extraValue: Int
extraValue = if (sortDiff > 0) {
val extraValue: Int = if (sortDiff > 0) {
// descent sorted by time
count - 1 - position
} else {

View File

@ -309,8 +309,7 @@ object DataStoreUtils {
}
fun getAccountDisplayName(context: Context, accountKey: UserKey, nameFirst: Boolean): String? {
val name: String?
name = if (nameFirst) {
val name: String? = if (nameFirst) {
getAccountName(context, accountKey)
} else {
"@${getAccountScreenName(context, accountKey)}"

View File

@ -46,12 +46,7 @@ class ExternalThemeManager(private val context: Context, private val preferences
fun reloadEmojiPreferences() {
val emojiComponentName = preferences.getString(KEY_EMOJI_SUPPORT, null)
emojiPackageName = if (emojiComponentName != null) {
val componentName = ComponentName.unflattenFromString(emojiComponentName)
if (componentName != null) {
componentName.packageName
} else {
null
}
ComponentName.unflattenFromString(emojiComponentName)?.packageName
} else {
null
}

View File

@ -124,8 +124,8 @@ object MenuUtils {
val retweetHighlight = ContextCompat.getColor(context, R.color.highlight_retweet)
val favoriteHighlight = ContextCompat.getColor(context, R.color.highlight_favorite)
val likeHighlight = ContextCompat.getColor(context, R.color.highlight_like)
val isMyRetweet: Boolean
isMyRetweet = if (RetweetStatusTask.isCreatingRetweet(status.account_key, status.id)) {
val isMyRetweet: Boolean =
if (RetweetStatusTask.isCreatingRetweet(status.account_key, status.id)) {
true
} else if (twitter.isDestroyingStatus(status.account_key, status.id)) {
false
@ -164,8 +164,8 @@ object MenuUtils {
}
val favorite = menu.findItem(R.id.favorite)
if (favorite != null) {
val isFavorite: Boolean
isFavorite = if (CreateFavoriteTask.isCreatingFavorite(status.account_key, status.id)) {
val isFavorite: Boolean =
if (CreateFavoriteTask.isCreatingFavorite(status.account_key, status.id)) {
true
} else if (DestroyFavoriteTask.isDestroyingFavorite(status.account_key, status.id)) {
false

View File

@ -456,8 +456,7 @@ object Utils {
}
fun getInsetsTopWithoutActionBarHeight(context: Context, top: Int): Int {
val actionBarHeight: Int
actionBarHeight = if (context is AppCompatActivity) {
val actionBarHeight: Int = if (context is AppCompatActivity) {
getActionBarHeight(context.supportActionBar)
} else if (context is Activity) {
getActionBarHeight(context.actionBar)
@ -576,9 +575,8 @@ object Utils {
* @param message String
*/
fun sendPebbleNotification(context: Context, title: String?, message: String) {
val appName: String
appName = if (title == null) {
val appName: String = if (title == null) {
context.getString(R.string.app_name)
} else {
"${context.getString(R.string.app_name)} - $title"

View File

@ -303,8 +303,7 @@ class TwidereDns(val context: Context, private val preferences: SharedPreference
@Throws(UnknownHostException::class)
private fun addrFromRecord(name: String, r: Record): InetAddress {
val addr: InetAddress
addr = if (r is ARecord) {
val addr: InetAddress = if (r is ARecord) {
r.address
} else {
(r as AAAARecord).address

View File

@ -12,8 +12,7 @@ import org.mariotaku.twidere.util.ThemeUtils
*/
fun getCurrentThemeResource(context: Context, theme: String, fromThemeResource: Int = 0): Int {
val a: TypedArray
a = if (fromThemeResource == 0) {
val a: TypedArray = if (fromThemeResource == 0) {
context.obtainStyledAttributes(R.styleable.TwidereTheme)
} else {
context.obtainStyledAttributes(fromThemeResource, R.styleable.TwidereTheme)

View File

@ -97,8 +97,7 @@ class ActionIconThemedTextView(
for (d in TextViewSupport.getCompoundDrawablesRelative(this)) {
if (d == null) continue
d.mutate()
val color: Int
color = if (isActivated) {
val color: Int = if (isActivated) {
activatedColor
} else if (isEnabled) {
defaultColor

View File

@ -53,7 +53,6 @@ class PromotionOfferViewController : PremiumDashboardActivity.ExtraFeatureViewCo
private fun enablePromotions() {
preferences[promotionsEnabledKey] = true
val activity = ChameleonUtils.getActivity(context)
activity?.recreate()
ChameleonUtils.getActivity(context)?.recreate()
}
}

View File

@ -202,9 +202,7 @@ class DetailStatusViewHolder(
itemView.profileContainer.drawStart(colorNameManager.getUserColor(status.user_key))
val timestamp: Long
timestamp = if (status.is_retweet) {
val timestamp: Long = if (status.is_retweet) {
status.retweet_timestamp
} else {
status.timestamp
@ -736,8 +734,7 @@ class DetailStatusViewHolder(
}
fun displayCount(count: LabeledCount, hideNumbers: Boolean) {
val label: String
label = when (count.type) {
val label: String = when (count.type) {
KEY_REPLY_COUNT -> {
adapter.context.getString(R.string.replies)
}