mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-16 19:50:53 +01:00
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)) {
|
if (checkAllSelfPermissionsGranted(AndroidPermissions.WRITE_EXTERNAL_STORAGE)) {
|
||||||
saveToStorage()
|
saveToStorage()
|
||||||
} else {
|
} else {
|
||||||
val permissions: Array<String>
|
val permissions: Array<String> = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
||||||
arrayOf(AndroidPermissions.WRITE_EXTERNAL_STORAGE, AndroidPermissions.READ_EXTERNAL_STORAGE)
|
arrayOf(AndroidPermissions.WRITE_EXTERNAL_STORAGE, AndroidPermissions.READ_EXTERNAL_STORAGE)
|
||||||
} else {
|
} else {
|
||||||
arrayOf(AndroidPermissions.WRITE_EXTERNAL_STORAGE)
|
arrayOf(AndroidPermissions.WRITE_EXTERNAL_STORAGE)
|
||||||
|
@ -177,23 +177,14 @@ class TrendsLocationSelectorActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getGroupView(groupPosition: Int, isExpanded: Boolean, convertView: View?, parent: ViewGroup): View {
|
override fun getGroupView(groupPosition: Int, isExpanded: Boolean, convertView: View?, parent: ViewGroup): View {
|
||||||
val view: View
|
val view: View = convertView ?: inflater.inflate(android.R.layout.simple_expandable_list_item_1, parent, false)
|
||||||
view = if (convertView != null) {
|
|
||||||
convertView
|
|
||||||
} else {
|
|
||||||
inflater.inflate(android.R.layout.simple_expandable_list_item_1, parent, false)
|
|
||||||
}
|
|
||||||
view.findViewById<TextView>(android.R.id.text1).text = getGroup(groupPosition).name
|
view.findViewById<TextView>(android.R.id.text1).text = getGroup(groupPosition).name
|
||||||
return view
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getChildView(groupPosition: Int, childPosition: Int, isLastChild: Boolean, convertView: View?, parent: ViewGroup): View {
|
override fun getChildView(groupPosition: Int, childPosition: Int, isLastChild: Boolean, convertView: View?, parent: ViewGroup): View {
|
||||||
val view: View
|
val view: View =
|
||||||
view = if (convertView != null) {
|
convertView ?: inflater.inflate(android.R.layout.simple_list_item_1, parent, false)
|
||||||
convertView
|
|
||||||
} else {
|
|
||||||
inflater.inflate(android.R.layout.simple_list_item_1, parent, false)
|
|
||||||
}
|
|
||||||
val location = getChild(groupPosition, childPosition)
|
val location = getChild(groupPosition, childPosition)
|
||||||
val text1 = view.findViewById<TextView>(android.R.id.text1)
|
val text1 = view.findViewById<TextView>(android.R.id.text1)
|
||||||
if (location.parentId == WORLDWIDE) {
|
if (location.parentId == WORLDWIDE) {
|
||||||
|
@ -36,11 +36,7 @@ class SimpleParcelableUsersAdapter(
|
|||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
override fun getItemId(position: Int): Long {
|
||||||
val item = getItem(position)
|
val item = getItem(position)
|
||||||
return if (item != null) {
|
return item?.hashCode()?.toLong() ?: -1
|
||||||
item.hashCode().toLong()
|
|
||||||
} else {
|
|
||||||
-1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
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 {
|
fun Credentials.getEndpoint(cls: Class<*>): Endpoint {
|
||||||
val apiUrlFormat: String
|
|
||||||
val noVersionSuffix = this.no_version_suffix
|
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
|
this.api_url_format
|
||||||
} else {
|
} else {
|
||||||
DEFAULT_TWITTER_API_URL_FORMAT
|
DEFAULT_TWITTER_API_URL_FORMAT
|
||||||
@ -113,8 +112,7 @@ fun Credentials.getEndpoint(cls: Class<*>): Endpoint {
|
|||||||
}
|
}
|
||||||
val endpointUrl = MicroBlogAPIFactory.getApiUrl(apiUrlFormat, domain, versionSuffix)
|
val endpointUrl = MicroBlogAPIFactory.getApiUrl(apiUrlFormat, domain, versionSuffix)
|
||||||
if (this is OAuthCredentials) {
|
if (this is OAuthCredentials) {
|
||||||
val signEndpointUrl: String
|
val signEndpointUrl: String = if (same_oauth_signing_url) {
|
||||||
signEndpointUrl = if (same_oauth_signing_url) {
|
|
||||||
endpointUrl
|
endpointUrl
|
||||||
} else {
|
} else {
|
||||||
MicroBlogAPIFactory.getApiUrl(DEFAULT_TWITTER_API_URL_FORMAT, domain, versionSuffix)
|
MicroBlogAPIFactory.getApiUrl(DEFAULT_TWITTER_API_URL_FORMAT, domain, versionSuffix)
|
||||||
|
@ -61,11 +61,8 @@ class ColorPickerDialogFragment : BaseDialogFragment(), DialogInterface.OnClickL
|
|||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val color: Int
|
val color: Int
|
||||||
val args = arguments
|
val args = arguments
|
||||||
color = if (savedInstanceState != null) {
|
color =
|
||||||
savedInstanceState.getInt(EXTRA_COLOR, Color.WHITE)
|
savedInstanceState?.getInt(EXTRA_COLOR, Color.WHITE) ?: args!!.getInt(EXTRA_COLOR, Color.WHITE)
|
||||||
} else {
|
|
||||||
args!!.getInt(EXTRA_COLOR, Color.WHITE)
|
|
||||||
}
|
|
||||||
|
|
||||||
val activity = activity
|
val activity = activity
|
||||||
val builder = AlertDialog.Builder(requireActivity())
|
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) {
|
override fun onItemClick(view: AdapterView<*>, child: View, position: Int, id: Long) {
|
||||||
if (multiSelectManager.isActive) return
|
if (multiSelectManager.isActive) return
|
||||||
val trend: String?
|
val trend: String? = if (view is ListView) {
|
||||||
trend = if (view is ListView) {
|
|
||||||
adapter.getItem(position - view.headerViewsCount)
|
adapter.getItem(position - view.headerViewsCount)
|
||||||
} else {
|
} else {
|
||||||
adapter.getItem(position)
|
adapter.getItem(position)
|
||||||
|
@ -44,11 +44,7 @@ class AccountPreferences(
|
|||||||
val defaultNotificationLightColor: Int
|
val defaultNotificationLightColor: Int
|
||||||
get() {
|
get() {
|
||||||
val a = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true)
|
val a = AccountUtils.getAccountDetails(AccountManager.get(context), accountKey, true)
|
||||||
return if (a != null) {
|
return a?.color ?: ContextCompat.getColor(context, R.color.branding_color)
|
||||||
a.color
|
|
||||||
} else {
|
|
||||||
ContextCompat.getColor(context, R.color.branding_color)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val directMessagesNotificationType: Int
|
val directMessagesNotificationType: Int
|
||||||
|
@ -167,8 +167,7 @@ class CacheProvider : ContentProvider() {
|
|||||||
* Copied from ContentResolver.java
|
* Copied from ContentResolver.java
|
||||||
*/
|
*/
|
||||||
private fun modeToMode(mode: String): Int {
|
private fun modeToMode(mode: String): Int {
|
||||||
val modeBits: Int
|
val modeBits: Int = if ("r" == mode) {
|
||||||
modeBits = if ("r" == mode) {
|
|
||||||
ParcelFileDescriptor.MODE_READ_ONLY
|
ParcelFileDescriptor.MODE_READ_ONLY
|
||||||
} else if ("w" == mode || "wt" == mode) {
|
} else if ("w" == mode || "wt" == mode) {
|
||||||
ParcelFileDescriptor.MODE_WRITE_ONLY or ParcelFileDescriptor.MODE_CREATE or ParcelFileDescriptor.MODE_TRUNCATE
|
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) {
|
private fun handleUpdateStatusIntent(intent: Intent) {
|
||||||
val status = intent.getParcelableExtra<ParcelableStatusUpdate>(EXTRA_STATUS)
|
val status = intent.getParcelableExtra<ParcelableStatusUpdate>(EXTRA_STATUS)
|
||||||
val statusParcelables = intent.getNullableTypedArrayExtra<ParcelableStatusUpdate>(EXTRA_STATUSES)
|
|
||||||
val scheduleInfo = intent.getParcelableExtra<ScheduleInfo>(EXTRA_SCHEDULE_INFO)
|
val scheduleInfo = intent.getParcelableExtra<ScheduleInfo>(EXTRA_SCHEDULE_INFO)
|
||||||
val statuses: Array<ParcelableStatusUpdate>
|
val statuses: Array<ParcelableStatusUpdate>
|
||||||
statuses = if (statusParcelables != null) {
|
statuses = intent.getNullableTypedArrayExtra(EXTRA_STATUSES)
|
||||||
statusParcelables
|
?: if (status != null) {
|
||||||
} else if (status != null) {
|
arrayOf(status)
|
||||||
arrayOf(status)
|
} else
|
||||||
} else
|
return
|
||||||
return
|
|
||||||
@Draft.Action
|
@Draft.Action
|
||||||
val actionType = intent.getStringExtra(EXTRA_ACTION)
|
val actionType = intent.getStringExtra(EXTRA_ACTION)
|
||||||
statuses.forEach { it.draft_action = actionType }
|
statuses.forEach { it.draft_action = actionType }
|
||||||
|
@ -228,8 +228,7 @@ abstract class GetStatusesTask(
|
|||||||
fun getPositionKey(timestamp: Long, sortId: Long, lastSortId: Long, sortDiff: Long,
|
fun getPositionKey(timestamp: Long, sortId: Long, lastSortId: Long, sortDiff: Long,
|
||||||
position: Int, count: Int): Long {
|
position: Int, count: Int): Long {
|
||||||
if (sortDiff == 0L) return timestamp
|
if (sortDiff == 0L) return timestamp
|
||||||
val extraValue: Int
|
val extraValue: Int = if (sortDiff > 0) {
|
||||||
extraValue = if (sortDiff > 0) {
|
|
||||||
// descent sorted by time
|
// descent sorted by time
|
||||||
count - 1 - position
|
count - 1 - position
|
||||||
} else {
|
} else {
|
||||||
|
@ -309,8 +309,7 @@ object DataStoreUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getAccountDisplayName(context: Context, accountKey: UserKey, nameFirst: Boolean): String? {
|
fun getAccountDisplayName(context: Context, accountKey: UserKey, nameFirst: Boolean): String? {
|
||||||
val name: String?
|
val name: String? = if (nameFirst) {
|
||||||
name = if (nameFirst) {
|
|
||||||
getAccountName(context, accountKey)
|
getAccountName(context, accountKey)
|
||||||
} else {
|
} else {
|
||||||
"@${getAccountScreenName(context, accountKey)}"
|
"@${getAccountScreenName(context, accountKey)}"
|
||||||
|
@ -46,12 +46,7 @@ class ExternalThemeManager(private val context: Context, private val preferences
|
|||||||
fun reloadEmojiPreferences() {
|
fun reloadEmojiPreferences() {
|
||||||
val emojiComponentName = preferences.getString(KEY_EMOJI_SUPPORT, null)
|
val emojiComponentName = preferences.getString(KEY_EMOJI_SUPPORT, null)
|
||||||
emojiPackageName = if (emojiComponentName != null) {
|
emojiPackageName = if (emojiComponentName != null) {
|
||||||
val componentName = ComponentName.unflattenFromString(emojiComponentName)
|
ComponentName.unflattenFromString(emojiComponentName)?.packageName
|
||||||
if (componentName != null) {
|
|
||||||
componentName.packageName
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
@ -124,8 +124,8 @@ object MenuUtils {
|
|||||||
val retweetHighlight = ContextCompat.getColor(context, R.color.highlight_retweet)
|
val retweetHighlight = ContextCompat.getColor(context, R.color.highlight_retweet)
|
||||||
val favoriteHighlight = ContextCompat.getColor(context, R.color.highlight_favorite)
|
val favoriteHighlight = ContextCompat.getColor(context, R.color.highlight_favorite)
|
||||||
val likeHighlight = ContextCompat.getColor(context, R.color.highlight_like)
|
val likeHighlight = ContextCompat.getColor(context, R.color.highlight_like)
|
||||||
val isMyRetweet: Boolean
|
val isMyRetweet: Boolean =
|
||||||
isMyRetweet = if (RetweetStatusTask.isCreatingRetweet(status.account_key, status.id)) {
|
if (RetweetStatusTask.isCreatingRetweet(status.account_key, status.id)) {
|
||||||
true
|
true
|
||||||
} else if (twitter.isDestroyingStatus(status.account_key, status.id)) {
|
} else if (twitter.isDestroyingStatus(status.account_key, status.id)) {
|
||||||
false
|
false
|
||||||
@ -164,8 +164,8 @@ object MenuUtils {
|
|||||||
}
|
}
|
||||||
val favorite = menu.findItem(R.id.favorite)
|
val favorite = menu.findItem(R.id.favorite)
|
||||||
if (favorite != null) {
|
if (favorite != null) {
|
||||||
val isFavorite: Boolean
|
val isFavorite: Boolean =
|
||||||
isFavorite = if (CreateFavoriteTask.isCreatingFavorite(status.account_key, status.id)) {
|
if (CreateFavoriteTask.isCreatingFavorite(status.account_key, status.id)) {
|
||||||
true
|
true
|
||||||
} else if (DestroyFavoriteTask.isDestroyingFavorite(status.account_key, status.id)) {
|
} else if (DestroyFavoriteTask.isDestroyingFavorite(status.account_key, status.id)) {
|
||||||
false
|
false
|
||||||
|
@ -456,8 +456,7 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getInsetsTopWithoutActionBarHeight(context: Context, top: Int): Int {
|
fun getInsetsTopWithoutActionBarHeight(context: Context, top: Int): Int {
|
||||||
val actionBarHeight: Int
|
val actionBarHeight: Int = if (context is AppCompatActivity) {
|
||||||
actionBarHeight = if (context is AppCompatActivity) {
|
|
||||||
getActionBarHeight(context.supportActionBar)
|
getActionBarHeight(context.supportActionBar)
|
||||||
} else if (context is Activity) {
|
} else if (context is Activity) {
|
||||||
getActionBarHeight(context.actionBar)
|
getActionBarHeight(context.actionBar)
|
||||||
@ -576,9 +575,8 @@ object Utils {
|
|||||||
* @param message String
|
* @param message String
|
||||||
*/
|
*/
|
||||||
fun sendPebbleNotification(context: Context, title: String?, 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)
|
context.getString(R.string.app_name)
|
||||||
} else {
|
} else {
|
||||||
"${context.getString(R.string.app_name)} - $title"
|
"${context.getString(R.string.app_name)} - $title"
|
||||||
|
@ -303,8 +303,7 @@ class TwidereDns(val context: Context, private val preferences: SharedPreference
|
|||||||
|
|
||||||
@Throws(UnknownHostException::class)
|
@Throws(UnknownHostException::class)
|
||||||
private fun addrFromRecord(name: String, r: Record): InetAddress {
|
private fun addrFromRecord(name: String, r: Record): InetAddress {
|
||||||
val addr: InetAddress
|
val addr: InetAddress = if (r is ARecord) {
|
||||||
addr = if (r is ARecord) {
|
|
||||||
r.address
|
r.address
|
||||||
} else {
|
} else {
|
||||||
(r as AAAARecord).address
|
(r as AAAARecord).address
|
||||||
|
@ -12,8 +12,7 @@ import org.mariotaku.twidere.util.ThemeUtils
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
fun getCurrentThemeResource(context: Context, theme: String, fromThemeResource: Int = 0): Int {
|
fun getCurrentThemeResource(context: Context, theme: String, fromThemeResource: Int = 0): Int {
|
||||||
val a: TypedArray
|
val a: TypedArray = if (fromThemeResource == 0) {
|
||||||
a = if (fromThemeResource == 0) {
|
|
||||||
context.obtainStyledAttributes(R.styleable.TwidereTheme)
|
context.obtainStyledAttributes(R.styleable.TwidereTheme)
|
||||||
} else {
|
} else {
|
||||||
context.obtainStyledAttributes(fromThemeResource, R.styleable.TwidereTheme)
|
context.obtainStyledAttributes(fromThemeResource, R.styleable.TwidereTheme)
|
||||||
|
@ -97,8 +97,7 @@ class ActionIconThemedTextView(
|
|||||||
for (d in TextViewSupport.getCompoundDrawablesRelative(this)) {
|
for (d in TextViewSupport.getCompoundDrawablesRelative(this)) {
|
||||||
if (d == null) continue
|
if (d == null) continue
|
||||||
d.mutate()
|
d.mutate()
|
||||||
val color: Int
|
val color: Int = if (isActivated) {
|
||||||
color = if (isActivated) {
|
|
||||||
activatedColor
|
activatedColor
|
||||||
} else if (isEnabled) {
|
} else if (isEnabled) {
|
||||||
defaultColor
|
defaultColor
|
||||||
|
@ -53,7 +53,6 @@ class PromotionOfferViewController : PremiumDashboardActivity.ExtraFeatureViewCo
|
|||||||
|
|
||||||
private fun enablePromotions() {
|
private fun enablePromotions() {
|
||||||
preferences[promotionsEnabledKey] = true
|
preferences[promotionsEnabledKey] = true
|
||||||
val activity = ChameleonUtils.getActivity(context)
|
ChameleonUtils.getActivity(context)?.recreate()
|
||||||
activity?.recreate()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -202,9 +202,7 @@ class DetailStatusViewHolder(
|
|||||||
|
|
||||||
itemView.profileContainer.drawStart(colorNameManager.getUserColor(status.user_key))
|
itemView.profileContainer.drawStart(colorNameManager.getUserColor(status.user_key))
|
||||||
|
|
||||||
val timestamp: Long
|
val timestamp: Long = if (status.is_retweet) {
|
||||||
|
|
||||||
timestamp = if (status.is_retweet) {
|
|
||||||
status.retweet_timestamp
|
status.retweet_timestamp
|
||||||
} else {
|
} else {
|
||||||
status.timestamp
|
status.timestamp
|
||||||
@ -736,8 +734,7 @@ class DetailStatusViewHolder(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun displayCount(count: LabeledCount, hideNumbers: Boolean) {
|
fun displayCount(count: LabeledCount, hideNumbers: Boolean) {
|
||||||
val label: String
|
val label: String = when (count.type) {
|
||||||
label = when (count.type) {
|
|
||||||
KEY_REPLY_COUNT -> {
|
KEY_REPLY_COUNT -> {
|
||||||
adapter.context.getString(R.string.replies)
|
adapter.context.getString(R.string.replies)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user