コード整形

This commit is contained in:
tateisu 2023-07-20 11:40:12 +09:00
parent 55fb631952
commit 4fc6442c37
14 changed files with 87 additions and 101 deletions

View File

@ -171,7 +171,7 @@ dependencies {
implementation project(":anko") implementation project(":anko")
implementation fileTree(include: ["*.aar"], dir: "src/main/libs") implementation fileTree(include: ["*.aar"], dir: "src/main/libs")
fcmImplementation "com.google.firebase:firebase-messaging:23.1.2" fcmImplementation "com.google.firebase:firebase-messaging:23.2.0"
fcmImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$kotlinxCoroutinesVersion" fcmImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:$kotlinxCoroutinesVersion"
// implementation "org.conscrypt:conscrypt-android:$conscryptVersion" // implementation "org.conscrypt:conscrypt-android:$conscryptVersion"

View File

@ -65,7 +65,7 @@ class TestTootInstance {
/* /*
TootInstance.get() はアカウントを指定する場合とホストを指定する場合がある TootInstance.get() はアカウントを指定する場合とホストを指定する場合がある
ホスト指定とアカウント指定 MastodonとMisskey で試す ホスト指定とアカウント指定 MastodonとMisskey で試す
*/ */
@Test @Test
fun instanceByHostname() = runTest { fun instanceByHostname() = runTest {

View File

@ -692,7 +692,10 @@ class ActAppSetting : AppCompatActivity(), ColorPickerDialogListener, View.OnCli
etEditText.setText(text) etEditText.setText(text)
etEditText.setSelection(0, text.length) etEditText.setSelection(0, text.length)
item.showEditText.invoke(actAppSetting,views.etEditText) item.showEditText.invoke(
actAppSetting,
views.etEditText
)
} }
updateErrorView() updateErrorView()
} }

View File

@ -2,7 +2,6 @@ package jp.juggler.subwaytooter
import android.app.Activity import android.app.Activity
import android.app.Dialog import android.app.Dialog
import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Typeface import android.graphics.Typeface
@ -627,30 +626,29 @@ class ActMain : AppCompatActivity(),
super.onResume() super.onResume()
/* /*
super.onResume() から呼ばれる isTopOfTask() android.os.RemoteException 例外をたまに出すが放置することにした super.onResume() から呼ばれる isTopOfTask() android.os.RemoteException 例外をたまに出すが放置することにした
java.lang.RuntimeException:
java.lang.RuntimeException: at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4430)
at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4430) at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:4470)
at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:4470) Caused by: java.lang.IllegalArgumentException:
Caused by: java.lang.IllegalArgumentException: at android.os.Parcel.createException (Parcel.java:1957)
at android.os.Parcel.createException (Parcel.java:1957) at android.os.Parcel.readException (Parcel.java:1921)
at android.os.Parcel.readException (Parcel.java:1921) at android.os.Parcel.readException (Parcel.java:1871)
at android.os.Parcel.readException (Parcel.java:1871) at android.app.IActivityManager$Stub$Proxy.isTopOfTask (IActivityManager.java:7912)
at android.app.IActivityManager$Stub$Proxy.isTopOfTask (IActivityManager.java:7912) at android.app.Activity.isTopOfTask (Activity.java:6724)
at android.app.Activity.isTopOfTask (Activity.java:6724) at android.app.Activity.onResume (Activity.java:1425)
at android.app.Activity.onResume (Activity.java:1425) at androidx.fragment.app.FragmentActivity.onResume (FragmentActivity.java:456)
at androidx.fragment.app.FragmentActivity.onResume (FragmentActivity.java:456) at jp.juggler.subwaytooter.ActMain.onResume (ActMain.kt:685)
at jp.juggler.subwaytooter.ActMain.onResume (ActMain.kt:685) at android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1456)
at android.app.Instrumentation.callActivityOnResume (Instrumentation.java:1456) at android.app.Activity.performResume (Activity.java:7614)
at android.app.Activity.performResume (Activity.java:7614) at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4412)
at android.app.ActivityThread.performResumeActivity (ActivityThread.java:4412) Caused by: android.os.RemoteException:
Caused by: android.os.RemoteException: at com.android.server.am.ActivityManagerService.isTopOfTask (ActivityManagerService.java:16128)
at com.android.server.am.ActivityManagerService.isTopOfTask (ActivityManagerService.java:16128) at android.app.IActivityManager$Stub.onTransact (IActivityManager.java:2376)
at android.app.IActivityManager$Stub.onTransact (IActivityManager.java:2376) at com.android.server.am.ActivityManagerService.onTransact (ActivityManagerService.java:3648)
at com.android.server.am.ActivityManagerService.onTransact (ActivityManagerService.java:3648) at com.android.server.am.HwActivityManagerService.onTransact (HwActivityManagerService.java:609)
at com.android.server.am.HwActivityManagerService.onTransact (HwActivityManagerService.java:609) at android.os.Binder.execTransact (Binder.java:739)
at android.os.Binder.execTransact (Binder.java:739) */
*/
if (PrefB.bpDontScreenOff.value) { if (PrefB.bpDontScreenOff.value) {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)

View File

@ -214,7 +214,7 @@ suspend fun <T : Any?, A : Context> A.runApiTask2(
progressPrefix: String? = null, progressPrefix: String? = null,
progressSetup: (progress: ProgressDialogEx) -> Unit = ApiTask.defaultProgressSetupCallback, progressSetup: (progress: ProgressDialogEx) -> Unit = ApiTask.defaultProgressSetupCallback,
backgroundBlock: suspend A.(client: TootApiClient) -> T, backgroundBlock: suspend A.(client: TootApiClient) -> T,
) :T = TootTaskRunner2.runApiTask( ): T = TootTaskRunner2.runApiTask(
this, this,
accessInfo, accessInfo,
null, null,

View File

@ -1,10 +1,12 @@
package jp.juggler.subwaytooter.api package jp.juggler.subwaytooter.api
import java.lang.Exception class TootApiResultException(val result: TootApiResult?) :
Exception(result?.error ?: "cancelled.") {
class TootApiResultException(val result: TootApiResult?) : Exception(result?.error ?: "cancelled.") {
constructor(error: String) : this(TootApiResult(error)) constructor(error: String) : this(TootApiResult(error))
} }
fun errorApiResult(result: TootApiResult?):Nothing = throw TootApiResultException(result) fun errorApiResult(result: TootApiResult?): Nothing =
fun errorApiResult(error:String):Nothing = throw TootApiResultException(error) throw TootApiResultException(result)
fun errorApiResult(error: String): Nothing =
throw TootApiResultException(error)

View File

@ -604,6 +604,7 @@ open class TootAccount(
apDomain = pair.second ?: error("can't get apDomain from acct or url") apDomain = pair.second ?: error("can't get apDomain from acct or url")
acct = Acct.parse(username, apDomain) acct = Acct.parse(username, apDomain)
} }
else -> error("serverType missmatch: ${parser.serviceType}") else -> error("serverType missmatch: ${parser.serviceType}")
} }
return TootAccount( return TootAccount(
@ -713,12 +714,9 @@ open class TootAccount(
// Tootsearch用。URLやUriを使ってアカウントのインスタンス名を調べる // Tootsearch用。URLやUriを使ってアカウントのインスタンス名を調べる
fun findHostFromUrl( fun findHostFromUrl(
acctArg: String?, acctArg: String?,
linkHelper: LinkHelper linkHelper: LinkHelper?,
?, url: String?,
url: String ): Pair<Host?, Host?> {
?,
)
: Pair<Host?, Host?> {
val apDomain = findApDomain(acctArg, linkHelper) val apDomain = findApDomain(acctArg, linkHelper)
val apiHost = findApiHost(url) val apiHost = findApiHost(url)
return Pair(apiHost ?: apDomain, apDomain ?: apiHost) return Pair(apiHost ?: apDomain, apDomain ?: apiHost)

View File

@ -356,7 +356,7 @@ private fun ItemViewHolder.showAttachments(status: TootStatus) {
} }
} }
val reUrlGif by lazy{ val reUrlGif by lazy {
"""\.gif(?:\z|\?|#)""" """\.gif(?:\z|\?|#)"""
.toRegex(RegexOption.IGNORE_CASE) .toRegex(RegexOption.IGNORE_CASE)
} }

View File

@ -38,8 +38,8 @@ abstract class PushBase {
subLog: SubscriptionLogger, subLog: SubscriptionLogger,
account: SavedAccount, account: SavedAccount,
willRemoveSubscription: Boolean, willRemoveSubscription: Boolean,
forceUpdate:Boolean, forceUpdate: Boolean,
):String? ): String?
// プッシュメッセージのJSONデータを通知用に整形 // プッシュメッセージのJSONデータを通知用に整形
abstract suspend fun formatPushMessage( abstract suspend fun formatPushMessage(

View File

@ -100,7 +100,7 @@ class AttachmentRequest(
if (mimeType == MIME_TYPE_GIF) { if (mimeType == MIME_TYPE_GIF) {
// GIFはそのまま投げる // GIFはそのまま投げる
return contentUriOpener(context.contentResolver, uri, mimeType, isImage = true) return contentUriOpener(context.contentResolver, uri, mimeType, isImage = true)
}else if (mimeType.startsWith("image")) { } else if (mimeType.startsWith("image")) {
// 静止画 // 静止画
return createResizedImageOpener() return createResizedImageOpener()
} }
@ -372,10 +372,11 @@ class AttachmentRequest(
private suspend fun createResizedAudioOpener(srcBytes: Long): InputStreamOpener { private suspend fun createResizedAudioOpener(srcBytes: Long): InputStreamOpener {
val instance = instance() val instance = instance()
val mediaConfig = mediaConfig() val mediaConfig = mediaConfig()
return when { return when {
mimeType.mimeTypeIsSupported(instance) && mimeType.mimeTypeIsSupported(instance) &&
goodAudioType.contains(mimeType) && goodAudioType.contains(mimeType) &&
srcBytes <= maxBytesVideo(instance,mediaConfig).toLong() -> contentUriOpener( srcBytes <= maxBytesVideo(instance, mediaConfig).toLong()
-> contentUriOpener(
context.contentResolver, context.contentResolver,
uri, uri,
mimeType, mimeType,
@ -402,5 +403,4 @@ class AttachmentRequest(
} }
} }
} }
} }

View File

@ -328,7 +328,7 @@ class AttachmentUploader(
val maxBytesImage = ar.maxBytesImage(instance, mediaConfig) val maxBytesImage = ar.maxBytesImage(instance, mediaConfig)
val opener = ar.createOpener() val opener = ar.createOpener()
try{ try {
if (opener.contentLength > maxBytesImage.toLong()) { if (opener.contentLength > maxBytesImage.toLong()) {
return@runApiTask TootApiResult( return@runApiTask TootApiResult(
@ -339,7 +339,8 @@ class AttachmentUploader(
) )
} }
val fileName = fixDocumentName(getDocumentName(safeContext.contentResolver, src.uri)) val fileName =
fixDocumentName(getDocumentName(safeContext.contentResolver, src.uri))
if (account.isMisskey) { if (account.isMisskey) {
TootApiResult("custom thumbnail is not supported on misskey account.") TootApiResult("custom thumbnail is not supported on misskey account.")
@ -367,7 +368,7 @@ class AttachmentUploader(
} }
result result
} }
}finally{ } finally {
opener.deleteTempFile() opener.deleteTempFile()
} }
} }

View File

@ -28,4 +28,3 @@ fun Context.getUserAgent(): String {
else -> userAgentDefault() else -> userAgentDefault()
} }
} }

View File

@ -76,10 +76,6 @@ comments:
complexity: complexity:
active: true active: true
CyclomaticComplexMethod:
active: false
threshold: 20
ComplexCondition: ComplexCondition:
active: true active: true
threshold: 8 threshold: 8
@ -88,13 +84,15 @@ complexity:
threshold: 10 threshold: 10
includeStaticDeclarations: false includeStaticDeclarations: false
includePrivateDeclarations: false includePrivateDeclarations: false
ComplexMethod:
active: true CyclomaticComplexMethod:
active: false
threshold: 100 threshold: 100
ignoreSingleWhenExpression: true ignoreSingleWhenExpression: true
ignoreSimpleWhenEntries: true ignoreSimpleWhenEntries: true
ignoreNestingFunctions: true ignoreNestingFunctions: true
nestingFunctions: ['run', 'let', 'apply', 'with', 'also', 'use', 'forEach', 'isNotNull', 'ifNull'] nestingFunctions: ['run', 'let', 'apply', 'with', 'also', 'use', 'forEach', 'isNotNull', 'ifNull']
LabeledExpression: LabeledExpression:
active: false active: false
ignoredLabels: [] ignoredLabels: []
@ -254,9 +252,6 @@ formatting:
android: false android: false
autoCorrect: true autoCorrect: true
MultiLineIfElse:
active: false
Wrapping: Wrapping:
active: false active: false
AnnotationOnSeparateLine: AnnotationOnSeparateLine:
@ -293,7 +288,6 @@ formatting:
active: false active: false
autoCorrect: true autoCorrect: true
indentSize: 4 indentSize: 4
continuationIndentSize: 4
MaximumLineLength: MaximumLineLength:
active: false active: false
maxLineLength: 120 maxLineLength: 120
@ -390,6 +384,10 @@ formatting:
# 誤検出があるので無効化 # 誤検出があるので無効化
active: false active: false
autoCorrect: true autoCorrect: true
BlockCommentInitialStarAlignment:
active: false
CommentWrapping:
active: false
naming: naming:
active: true active: true
@ -402,7 +400,6 @@ naming:
parameterPattern: '[a-z][A-Za-z0-9]*' parameterPattern: '[a-z][A-Za-z0-9]*'
privateParameterPattern: '[a-z][A-Za-z0-9]*' privateParameterPattern: '[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^' excludeClassPattern: '$^'
ignoreOverridden: true
excludes: excludes:
- '**/test/**' - '**/test/**'
- '**/androidTest/**' - '**/androidTest/**'
@ -433,14 +430,12 @@ naming:
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
functionPattern: '([a-z][a-zA-Z0-9]*)|(`.*`)' functionPattern: '([a-z][a-zA-Z0-9]*)|(`.*`)'
excludeClassPattern: '$^' excludeClassPattern: '$^'
ignoreOverridden: true
ignoreAnnotated: ['Composable'] ignoreAnnotated: ['Composable']
FunctionParameterNaming: FunctionParameterNaming:
active: true active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**'] excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
parameterPattern: '[a-z][A-Za-z0-9]*' parameterPattern: '[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^' excludeClassPattern: '$^'
ignoreOverridden: true
InvalidPackageDeclaration: InvalidPackageDeclaration:
active: false active: false
excludes: ['*.kts'] excludes: ['*.kts']
@ -495,7 +490,6 @@ naming:
variablePattern: '[a-z][A-Za-z0-9]*' variablePattern: '[a-z][A-Za-z0-9]*'
privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*'
excludeClassPattern: '$^' excludeClassPattern: '$^'
ignoreOverridden: true
performance: performance:
active: true active: true
@ -520,8 +514,6 @@ potential-bugs:
active: false active: false
DoubleMutabilityForCollection: DoubleMutabilityForCollection:
active: false active: false
DuplicateCaseInWhenExpression:
active: true
EqualsAlwaysReturnsTrueOrFalse: EqualsAlwaysReturnsTrueOrFalse:
active: true active: true
EqualsWithHashCodeExist: EqualsWithHashCodeExist:
@ -534,7 +526,7 @@ potential-bugs:
active: false active: false
IgnoredReturnValue: IgnoredReturnValue:
active: false active: false
restrictToAnnotatedMethods: true restrictToConfig: true
returnValueAnnotations: ['*.CheckReturnValue', '*.CheckResult'] returnValueAnnotations: ['*.CheckReturnValue', '*.CheckResult']
ImplicitDefaultLocale: ImplicitDefaultLocale:
active: true active: true
@ -554,13 +546,8 @@ potential-bugs:
ignoreOnClassesPattern: '' ignoreOnClassesPattern: ''
MapGetWithNotNullAssertionOperator: MapGetWithNotNullAssertionOperator:
active: false active: false
MissingWhenCase:
active: true
allowElseExpression: true
NullableToStringCall: NullableToStringCall:
active: false active: false
RedundantElseInWhen:
active: true
UnconditionalJumpStatementInLoop: UnconditionalJumpStatementInLoop:
active: false active: false
UnnecessaryNotNullOperator: UnnecessaryNotNullOperator:
@ -590,7 +577,7 @@ style:
active: false active: false
DataClassContainsFunctions: DataClassContainsFunctions:
active: false active: false
conversionFunctionPrefix: 'to' conversionFunctionPrefix: ['to']
DataClassShouldBeImmutable: DataClassShouldBeImmutable:
active: false active: false
DestructuringDeclarationWithTooManyEntries: DestructuringDeclarationWithTooManyEntries:
@ -608,8 +595,8 @@ style:
active: false active: false
includeLineWrapping: false includeLineWrapping: false
ForbiddenComment: ForbiddenComment:
active: true active: false
values: ['TODO:', 'FIXME:', 'STOPSHIP:'] # comments: ???
allowedPatterns: '' allowedPatterns: ''
ForbiddenImport: ForbiddenImport:
active: false active: false
@ -631,10 +618,6 @@ style:
- '**/jvmTest/**' - '**/jvmTest/**'
- '**/jsTest/**' - '**/jsTest/**'
- '**/iosTest/**' - '**/iosTest/**'
ForbiddenPublicDataClass:
active: true
excludes: ['**']
ignorePackages: ['*.internal', '*.internal.*']
ForbiddenVoid: ForbiddenVoid:
active: false active: false
ignoreOverridden: false ignoreOverridden: false
@ -643,14 +626,8 @@ style:
active: true active: true
ignoreOverridableFunction: true ignoreOverridableFunction: true
ignoreActualFunction: true ignoreActualFunction: true
excludedFunctions: 'describeContents' excludedFunctions: ['describeContents']
ignoreAnnotated: ['dagger.Provides'] ignoreAnnotated: ['dagger.Provides']
LibraryCodeMustSpecifyReturnType:
active: true
excludes: ['**']
LibraryEntitiesShouldNotBePublic:
active: true
excludes: ['**']
LoopWithTooManyJumpStatements: LoopWithTooManyJumpStatements:
active: true active: true
maxJumpCount: 10 maxJumpCount: 10
@ -668,8 +645,6 @@ style:
ignoreEnums: false ignoreEnums: false
ignoreRanges: false ignoreRanges: false
ignoreExtensionFunctions: true ignoreExtensionFunctions: true
MandatoryBracesIfStatements:
active: false
MandatoryBracesLoops: MandatoryBracesLoops:
active: false active: false
MaxLineLength: MaxLineLength:
@ -711,7 +686,7 @@ style:
ReturnCount: ReturnCount:
active: false active: false
max: 10 max: 10
excludedFunctions: 'equals' excludedFunctions: ['equals']
excludeLabeled: false excludeLabeled: false
excludeReturnFromLambda: true excludeReturnFromLambda: true
excludeGuardClauses: false excludeGuardClauses: false
@ -790,3 +765,7 @@ style:
- java.util.* - java.util.*
- kotlinx.android.synthetic.* - kotlinx.android.synthetic.*
- android.content.* - android.content.*
UnusedPrivateProperty:
active: false
UnusedParameter:
active: false

View File

@ -6,25 +6,31 @@ use warnings;
my $inFile = "app/build/reports/detekt/st-detektAll.txt"; my $inFile = "app/build/reports/detekt/st-detektAll.txt";
my $rv = system qq(./gradlew :app:detektAll); my $rv = system qq(./gradlew :app:detektAll);
$rv == 256 and $rv =0;
$rv and die "gradle failed."; $rv and die "gradle failed.";
my @lines; say "#############################################";
say "# reading $inFile ...";
my @lines;
open(my $fh, "<:encoding(UTF-8)",$inFile) or die "$! $inFile"; open(my $fh, "<:encoding(UTF-8)",$inFile) or die "$! $inFile";
while(<$fh>){ while(<$fh>){
s/[\x0d\x0a]+//; s/[\x0d\x0a]+//;
next if not length; next if not length;
s|\\|/|g;
# TopLevelPropertyNaming - [wild] at Z:\mastodon-related\SubwayTooter\app\src\main\java\jp\juggler\subwaytooter\util\MimeTypeUtils.kt:118:19 - Signature=MimeTypeUtils.kt$private const val wild = '?'.code.toByte()
if(not /\A(.+) at (\S+?:\d+:\d+) - (.+)/){ # SpacingAroundCurly - [<anonymous>] at Z:\mastodon-related\SubwayTooter\app\src\main\java\jp\juggler\subwaytooter\itemviewholder\ItemViewHolderShowStatus.kt:359:21 - Signature=ItemViewHolderShowStatus.kt${
say "?? $_"; if( m|\A(\S+) - \[([^]]+)\] at (\S+)|){
my($name,$obj,$pos)=($1,$2,$3);
$pos =~ s|\A.*?/SubwayTooter/||;
push @lines,"$pos $name [$obj]";
next; next;
} }
my($name,$pos,$other)=($1,$2,$3); die "parse error: ?? $_";
$pos =~ s|\A.+\\SubwayTooter\\||;
$pos =~ s|\\|/|g;
push @lines, "$pos $name $other";
} }
say $_ for sort @lines;
say "#############################################";
say "# result:";
@lines or say "no problems found."; @lines or say "no problems found.";
say $_ for sort @lines;