From 57b9cf02520649ce91b62fdcbe917e2d44ccb979 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Mon, 23 Mar 2020 08:51:19 +0100 Subject: [PATCH] fix some lint warnings --- .../android/sliceviewer/util/SliceViewKtx.kt | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/SliceViewerKotlin/app/src/main/java/com/example/android/sliceviewer/util/SliceViewKtx.kt b/SliceViewerKotlin/app/src/main/java/com/example/android/sliceviewer/util/SliceViewKtx.kt index 78e6f6a11..3d824f561 100644 --- a/SliceViewerKotlin/app/src/main/java/com/example/android/sliceviewer/util/SliceViewKtx.kt +++ b/SliceViewerKotlin/app/src/main/java/com/example/android/sliceviewer/util/SliceViewKtx.kt @@ -30,17 +30,16 @@ import androidx.slice.core.SliceHints import androidx.slice.widget.SliceLiveData import androidx.slice.widget.SliceView import androidx.slice.widget.SliceView.OnSliceActionListener -import com.example.android.sliceviewer.ui.list.SliceViewerActivity import com.example.android.sliceviewer.ui.list.SliceViewerActivity.Companion.TAG fun SliceView.bind( - context: Context, - lifecycleOwner: LifecycleOwner, - uri: Uri, - onSliceActionListener: OnSliceActionListener = OnSliceActionListener { _, _ -> }, - onClickListener: OnClickListener = OnClickListener { }, - onLongClickListener: OnLongClickListener = OnLongClickListener { false }, - scrollable: Boolean = false + context: Context, + lifecycleOwner: LifecycleOwner, + uri: Uri, + onSliceActionListener: OnSliceActionListener = OnSliceActionListener { _, _ -> }, + onClickListener: OnClickListener = OnClickListener { }, + onLongClickListener: OnLongClickListener = OnLongClickListener { false }, + scrollable: Boolean = false ) { setOnSliceActionListener(onSliceActionListener) setOnClickListener(onClickListener) @@ -52,40 +51,36 @@ fun SliceView.bind( } // If someone accidentally prepends the "slice-" prefix to their scheme, let's remove it. val scheme = - if (uri.scheme.startsWith("slice-")) { - uri.scheme.replace("slice-", "") - } - else { - uri.scheme - } + if (uri.scheme.startsWith("slice-")) { + uri.scheme.replace("slice-", "") + } else { + uri.scheme + } if (scheme == ContentResolver.SCHEME_CONTENT || - scheme.equals("https", true) || - scheme.equals("http", true) + scheme.equals("https", true) || + scheme.equals("http", true) ) { val intent = Intent(Intent.ACTION_VIEW, uri) val sliceLiveData = SliceLiveData.fromIntent(context, intent) - sliceLiveData?.removeObservers(lifecycleOwner) + sliceLiveData.removeObservers(lifecycleOwner) try { - sliceLiveData?.observe(lifecycleOwner, Observer { updatedSlice -> + sliceLiveData.observe(lifecycleOwner, Observer { updatedSlice -> if (updatedSlice == null) return@Observer slice = updatedSlice val expiry = SliceMetadata.from(context, updatedSlice).expiry if (expiry != SliceHints.INFINITY) { // Shows the updated text after the TTL expires. postDelayed( - { slice = updatedSlice }, - expiry - System.currentTimeMillis() + 15 + { slice = updatedSlice }, + expiry - System.currentTimeMillis() + 15 ) } - Log.d(SliceViewerActivity.TAG, "Update Slice: $updatedSlice") + Log.d(TAG, "Update Slice: $updatedSlice") }) } catch (e: Exception) { - Log.e( - SliceViewerActivity.TAG, - "Failed to find a valid ContentProvider for authority: $uri" - ) + Log.e(TAG, "Failed to find a valid ContentProvider for authority: $uri") } } else { - Log.w(SliceViewerActivity.TAG, "Invalid uri, skipping slice: $uri") + Log.w(TAG, "Invalid uri, skipping slice: $uri") } } \ No newline at end of file