Fold some if-thens
This commit is contained in:
parent
421147b465
commit
1ac1c58824
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -216,15 +216,13 @@ 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) {
|
||||
arrayOf(status)
|
||||
} else
|
||||
return
|
||||
statuses = intent.getNullableTypedArrayExtra(EXTRA_STATUSES)
|
||||
?: if (status != null) {
|
||||
arrayOf(status)
|
||||
} else
|
||||
return
|
||||
@Draft.Action
|
||||
val actionType = intent.getStringExtra(EXTRA_ACTION)
|
||||
statuses.forEach { it.draft_action = actionType }
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)}"
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue