From 84408330b030b3301cc3c25ce9b54a811c5ac387 Mon Sep 17 00:00:00 2001 From: phicdy Date: Sun, 7 Jul 2024 11:02:13 +0900 Subject: [PATCH] Fix lint error SearchView.SearchAutoComplete can only be accessed from within the same library group prefix --- .../articlelist/ArticlesListActivity.kt | 35 ++++++++++------- .../FavoriteArticlesListActivity.kt | 32 ++++++++++------ .../CuratedArticlesListActivity.kt | 36 +++++++++++------- .../feedsearch/FeedSearchActivity.kt | 38 +++++++++++-------- .../com/phicdy/mycuration/top/TopActivity.kt | 37 ++++++++++-------- 5 files changed, 109 insertions(+), 69 deletions(-) diff --git a/feature_article_list/src/main/java/com/phicdy/mycuration/articlelist/ArticlesListActivity.kt b/feature_article_list/src/main/java/com/phicdy/mycuration/articlelist/ArticlesListActivity.kt index ca033e6e4..43d6f7e30 100644 --- a/feature_article_list/src/main/java/com/phicdy/mycuration/articlelist/ArticlesListActivity.kt +++ b/feature_article_list/src/main/java/com/phicdy/mycuration/articlelist/ArticlesListActivity.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.Toolbar @@ -22,16 +23,17 @@ import kotlinx.coroutines.launch import javax.inject.Inject @AndroidEntryPoint -class ArticlesListActivity : AppCompatActivity(), ArticlesListFragment.OnArticlesListFragmentListener { +class ArticlesListActivity : AppCompatActivity(), + ArticlesListFragment.OnArticlesListFragmentListener { companion object { private const val TAG_FRAGMENT = "TAG_FRAGMENT" private const val RSS_ID = "RSS_ID" fun createIntent(context: Context, rssId: Int) = - Intent(context, ArticlesListActivity::class.java).apply { - putExtra(RSS_ID, rssId) - } + Intent(context, ArticlesListActivity::class.java).apply { + putExtra(RSS_ID, rssId) + } } private lateinit var searchView: SearchView @@ -52,8 +54,8 @@ class ArticlesListActivity : AppCompatActivity(), ArticlesListFragment.OnArticle if (savedInstanceState == null) { val fragment = ArticlesListFragment.newInstance(feedId) supportFragmentManager.beginTransaction() - .add(R.id.container, fragment, TAG_FRAGMENT) - .commit() + .add(R.id.container, fragment, TAG_FRAGMENT) + .commit() } lifecycleScope.launch { @@ -63,6 +65,7 @@ class ArticlesListActivity : AppCompatActivity(), ArticlesListFragment.OnArticle title = getString(R.string.all) fbTitle = getString(R.string.all) } + else -> { // Select a feed val prefMgr = PreferenceHelper @@ -76,7 +79,8 @@ class ArticlesListActivity : AppCompatActivity(), ArticlesListFragment.OnArticle initToolbar() fab = findViewById(R.id.fab_article_list) fab.setOnClickListener { - val fragment = supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? ArticlesListFragment + val fragment = + supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? ArticlesListFragment fragment?.onFabButtonClicked() TrackerHelper.sendButtonEvent(getString(R.string.scroll_article_list)) } @@ -102,8 +106,10 @@ class ArticlesListActivity : AppCompatActivity(), ArticlesListFragment.OnArticle val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager val searchMenuItem = menu.findItem(R.id.search_article) searchView = searchMenuItem.actionView as SearchView - searchView.setSearchableInfo(searchManager - .getSearchableInfo(componentName)) + searchView.setSearchableInfo( + searchManager + .getSearchableInfo(componentName) + ) searchView.queryHint = getString(R.string.search_article) searchView.setOnQueryTextFocusChangeListener { _, queryTextFocused -> if (!queryTextFocused) { @@ -118,7 +124,8 @@ class ArticlesListActivity : AppCompatActivity(), ArticlesListFragment.OnArticle override fun onQueryTextSubmit(query: String?): Boolean { if (query == null) return false - val intent = Intent(this@ArticlesListActivity, ArticleSearchResultActivity::class.java) + val intent = + Intent(this@ArticlesListActivity, ArticleSearchResultActivity::class.java) intent.action = Intent.ACTION_SEARCH intent.putExtra(SearchManager.QUERY, query) startActivity(intent) @@ -126,8 +133,8 @@ class ArticlesListActivity : AppCompatActivity(), ArticlesListFragment.OnArticle } }) val color = getThemeColor(R.attr.colorPrimary) - val searchAutoComplete = searchView - .findViewById(androidx.appcompat.R.id.search_src_text) as SearchView.SearchAutoComplete + val searchAutoComplete: TextView = + searchView.findViewById(androidx.appcompat.R.id.search_src_text) searchAutoComplete.setTextColor(color) searchAutoComplete.setHintTextColor(color) return true @@ -138,9 +145,11 @@ class ArticlesListActivity : AppCompatActivity(), ArticlesListFragment.OnArticle when (item.itemId) { R.id.all_read -> { TrackerHelper.sendButtonEvent(getString(R.string.read_all_articles)) - val fragment = supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? ArticlesListFragment + val fragment = + supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? ArticlesListFragment fragment?.handleAllRead() } + android.R.id.home -> finish() else -> { } diff --git a/feature_article_list/src/main/java/com/phicdy/mycuration/articlelist/FavoriteArticlesListActivity.kt b/feature_article_list/src/main/java/com/phicdy/mycuration/articlelist/FavoriteArticlesListActivity.kt index 8af1b9920..de6e65707 100644 --- a/feature_article_list/src/main/java/com/phicdy/mycuration/articlelist/FavoriteArticlesListActivity.kt +++ b/feature_article_list/src/main/java/com/phicdy/mycuration/articlelist/FavoriteArticlesListActivity.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.Toolbar @@ -16,13 +17,14 @@ import com.phicdy.mycuration.tracker.TrackerHelper import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class FavoriteArticlesListActivity : AppCompatActivity(), FavoriteArticlesListFragment.OnArticlesListFragmentListener { +class FavoriteArticlesListActivity : AppCompatActivity(), + FavoriteArticlesListFragment.OnArticlesListFragmentListener { companion object { private const val TAG_FRAGMENT = "TAG_FRAGMENT" fun createIntent(context: Context) = - Intent(context, FavoriteArticlesListActivity::class.java) + Intent(context, FavoriteArticlesListActivity::class.java) } private lateinit var searchView: SearchView @@ -36,8 +38,8 @@ class FavoriteArticlesListActivity : AppCompatActivity(), FavoriteArticlesListFr if (savedInstanceState == null) { val fragment = FavoriteArticlesListFragment.newInstance() supportFragmentManager.beginTransaction() - .add(R.id.container, fragment, TAG_FRAGMENT) - .commit() + .add(R.id.container, fragment, TAG_FRAGMENT) + .commit() } title = getString(R.string.favorite) @@ -46,7 +48,8 @@ class FavoriteArticlesListActivity : AppCompatActivity(), FavoriteArticlesListFr initToolbar() fab = findViewById(R.id.fab_article_list) fab.setOnClickListener { - val fragment = supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? FavoriteArticlesListFragment + val fragment = + supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? FavoriteArticlesListFragment fragment?.onFabButtonClicked() TrackerHelper.sendButtonEvent(getString(R.string.scroll_article_list)) } @@ -71,8 +74,10 @@ class FavoriteArticlesListActivity : AppCompatActivity(), FavoriteArticlesListFr val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager val searchMenuItem = menu.findItem(R.id.search_article) searchView = searchMenuItem.actionView as SearchView - searchView.setSearchableInfo(searchManager - .getSearchableInfo(componentName)) + searchView.setSearchableInfo( + searchManager + .getSearchableInfo(componentName) + ) searchView.queryHint = getString(R.string.search_article) searchView.setOnQueryTextFocusChangeListener { _, queryTextFocused -> if (!queryTextFocused) { @@ -87,7 +92,10 @@ class FavoriteArticlesListActivity : AppCompatActivity(), FavoriteArticlesListFr override fun onQueryTextSubmit(query: String?): Boolean { if (query == null) return false - val intent = Intent(this@FavoriteArticlesListActivity, ArticleSearchResultActivity::class.java) + val intent = Intent( + this@FavoriteArticlesListActivity, + ArticleSearchResultActivity::class.java + ) intent.action = Intent.ACTION_SEARCH intent.putExtra(SearchManager.QUERY, query) startActivity(intent) @@ -95,8 +103,8 @@ class FavoriteArticlesListActivity : AppCompatActivity(), FavoriteArticlesListFr } }) val color = getThemeColor(R.attr.colorPrimary) - val searchAutoComplete = searchView - .findViewById(androidx.appcompat.R.id.search_src_text) as SearchView.SearchAutoComplete + val searchAutoComplete: TextView = + searchView.findViewById(androidx.appcompat.R.id.search_src_text) searchAutoComplete.setTextColor(color) searchAutoComplete.setHintTextColor(color) return true @@ -107,9 +115,11 @@ class FavoriteArticlesListActivity : AppCompatActivity(), FavoriteArticlesListFr when (item.itemId) { R.id.all_read -> { TrackerHelper.sendButtonEvent(getString(R.string.read_all_articles)) - val fragment = supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? FavoriteArticlesListFragment + val fragment = + supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? FavoriteArticlesListFragment fragment?.handleAllRead() } + android.R.id.home -> finish() else -> { } diff --git a/feature_curated_article_list/src/main/java/com/phicdy/mycuration/curatedarticlelist/CuratedArticlesListActivity.kt b/feature_curated_article_list/src/main/java/com/phicdy/mycuration/curatedarticlelist/CuratedArticlesListActivity.kt index 116ef38a3..fd21a10a0 100644 --- a/feature_curated_article_list/src/main/java/com/phicdy/mycuration/curatedarticlelist/CuratedArticlesListActivity.kt +++ b/feature_curated_article_list/src/main/java/com/phicdy/mycuration/curatedarticlelist/CuratedArticlesListActivity.kt @@ -6,6 +6,7 @@ import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.Toolbar @@ -22,7 +23,8 @@ import kotlinx.coroutines.launch import javax.inject.Inject @AndroidEntryPoint -class CuratedArticlesListActivity : AppCompatActivity(), CuratedArticlesListFragment.OnArticlesListFragmentListener { +class CuratedArticlesListActivity : AppCompatActivity(), + CuratedArticlesListFragment.OnArticlesListFragmentListener { companion object { private const val DEFAULT_CURATION_ID = -1 @@ -30,9 +32,9 @@ class CuratedArticlesListActivity : AppCompatActivity(), CuratedArticlesListFrag private const val CURATION_ID = "CURATION_ID" fun createIntent(context: Context, curationId: Int) = - Intent(context, CuratedArticlesListActivity::class.java).apply { - putExtra(CURATION_ID, curationId) - } + Intent(context, CuratedArticlesListActivity::class.java).apply { + putExtra(CURATION_ID, curationId) + } } private lateinit var searchView: SearchView @@ -53,8 +55,8 @@ class CuratedArticlesListActivity : AppCompatActivity(), CuratedArticlesListFrag if (savedInstanceState == null) { val fragment = CuratedArticlesListFragment.newInstance(curationId) supportFragmentManager.beginTransaction() - .add(R.id.container, fragment, TAG_FRAGMENT) - .commit() + .add(R.id.container, fragment, TAG_FRAGMENT) + .commit() } lifecycleScope.launch { @@ -64,7 +66,8 @@ class CuratedArticlesListActivity : AppCompatActivity(), CuratedArticlesListFrag initToolbar() fab = findViewById(R.id.fab_article_list) fab.setOnClickListener { - val fragment = supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? CuratedArticlesListFragment + val fragment = + supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? CuratedArticlesListFragment fragment?.onFabButtonClicked() TrackerHelper.sendButtonEvent(getString(R.string.scroll_article_list)) } @@ -90,8 +93,10 @@ class CuratedArticlesListActivity : AppCompatActivity(), CuratedArticlesListFrag val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager val searchMenuItem = menu.findItem(R.id.search_article) searchView = searchMenuItem.actionView as SearchView - searchView.setSearchableInfo(searchManager - .getSearchableInfo(componentName)) + searchView.setSearchableInfo( + searchManager + .getSearchableInfo(componentName) + ) searchView.queryHint = getString(R.string.search_article) searchView.setOnQueryTextFocusChangeListener { _, queryTextFocused -> if (!queryTextFocused) { @@ -106,7 +111,10 @@ class CuratedArticlesListActivity : AppCompatActivity(), CuratedArticlesListFrag override fun onQueryTextSubmit(query: String?): Boolean { if (query == null) return false - val intent = Intent(this@CuratedArticlesListActivity, ArticleSearchResultActivity::class.java) + val intent = Intent( + this@CuratedArticlesListActivity, + ArticleSearchResultActivity::class.java + ) intent.action = Intent.ACTION_SEARCH intent.putExtra(SearchManager.QUERY, query) startActivity(intent) @@ -114,8 +122,8 @@ class CuratedArticlesListActivity : AppCompatActivity(), CuratedArticlesListFrag } }) val color = getThemeColor(R.attr.colorPrimary) - val searchAutoComplete = searchView - .findViewById(androidx.appcompat.R.id.search_src_text) as SearchView.SearchAutoComplete + val searchAutoComplete: TextView = + searchView.findViewById(androidx.appcompat.R.id.search_src_text) searchAutoComplete.setTextColor(color) searchAutoComplete.setHintTextColor(color) return true @@ -126,9 +134,11 @@ class CuratedArticlesListActivity : AppCompatActivity(), CuratedArticlesListFrag when (item.itemId) { R.id.all_read -> { TrackerHelper.sendButtonEvent(getString(R.string.read_all_articles)) - val fragment = supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? CuratedArticlesListFragment + val fragment = + supportFragmentManager.findFragmentByTag(TAG_FRAGMENT) as? CuratedArticlesListFragment fragment?.handleAllRead() } + android.R.id.home -> finish() else -> { } diff --git a/feature_feed_search/src/main/java/com/phicdy/mycuration/feedsearch/FeedSearchActivity.kt b/feature_feed_search/src/main/java/com/phicdy/mycuration/feedsearch/FeedSearchActivity.kt index e2e0459ab..cc837803d 100644 --- a/feature_feed_search/src/main/java/com/phicdy/mycuration/feedsearch/FeedSearchActivity.kt +++ b/feature_feed_search/src/main/java/com/phicdy/mycuration/feedsearch/FeedSearchActivity.kt @@ -15,6 +15,7 @@ import android.view.View import android.webkit.WebResourceRequest import android.webkit.WebView import android.webkit.WebViewClient +import android.widget.TextView import android.widget.Toast import androidx.activity.OnBackPressedCallback import androidx.annotation.StringRes @@ -83,7 +84,10 @@ class FeedSearchActivity : AppCompatActivity(), FeedSearchView, CoroutineScope { return false } - override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean { + override fun shouldOverrideUrlLoading( + view: WebView, + request: WebResourceRequest + ): Boolean { return false } @@ -136,10 +140,12 @@ class FeedSearchActivity : AppCompatActivity(), FeedSearchView, CoroutineScope { val color = getThemeColor(R.attr.colorPrimary) val searchManager = getSystemService(Context.SEARCH_SERVICE) as SearchManager - searchView.setSearchableInfo(searchManager - .getSearchableInfo(componentName)) - val searchAutoComplete = searchView - .findViewById(androidx.appcompat.R.id.search_src_text) as SearchView.SearchAutoComplete + searchView.setSearchableInfo( + searchManager + .getSearchableInfo(componentName) + ) + val searchAutoComplete: TextView = + searchView.findViewById(androidx.appcompat.R.id.search_src_text) searchAutoComplete.setTextColor(color) searchAutoComplete.setHintTextColor(color) @@ -157,20 +163,20 @@ class FeedSearchActivity : AppCompatActivity(), FeedSearchView, CoroutineScope { // Search tutorial sequence.addSequenceItem( MaterialShowcaseView.Builder(this@FeedSearchActivity) - .setTarget(view) - .setContentText(R.string.tutorial_search_rss_description) - .setDismissText(R.string.tutorial_next) - .build() + .setTarget(view) + .setContentText(R.string.tutorial_search_rss_description) + .setDismissText(R.string.tutorial_next) + .build() ) // Add button tutorial sequence.addSequenceItem( - MaterialShowcaseView.Builder(this@FeedSearchActivity) - .setTarget(fab) - .setContentText(R.string.tutorial_add_rss_description) - .setDismissText(R.string.tutorial_close) - .setDismissOnTouch(true) - .build() + MaterialShowcaseView.Builder(this@FeedSearchActivity) + .setTarget(fab) + .setContentText(R.string.tutorial_add_rss_description) + .setDismissText(R.string.tutorial_close) + .setDismissOnTouch(true) + .build() ) // Open software keyboard if tutorial already finished @@ -260,6 +266,6 @@ class FeedSearchActivity : AppCompatActivity(), FeedSearchView, CoroutineScope { @ActivityScoped @Provides fun provideFeedSearchView(@ActivityContext activity: Context): FeedSearchView = - activity as FeedSearchView + activity as FeedSearchView } } diff --git a/feature_top/src/main/java/com/phicdy/mycuration/top/TopActivity.kt b/feature_top/src/main/java/com/phicdy/mycuration/top/TopActivity.kt index 393b4ff5a..6b2d07d2a 100644 --- a/feature_top/src/main/java/com/phicdy/mycuration/top/TopActivity.kt +++ b/feature_top/src/main/java/com/phicdy/mycuration/top/TopActivity.kt @@ -15,6 +15,7 @@ import android.view.animation.AnimationUtils import android.widget.Button import android.widget.FrameLayout import android.widget.LinearLayout +import android.widget.TextView import androidx.activity.OnBackPressedCallback import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.viewModels @@ -144,20 +145,22 @@ class TopActivity : R.id.navigation_curation -> { supportActionBar?.title = getString(R.string.curation) supportFragmentManager.beginTransaction() - .replace(R.id.fr_content, CurationListFragment(), FRAGMENT_TAG) - .commit() + .replace(R.id.fr_content, CurationListFragment(), FRAGMENT_TAG) + .commit() } + R.id.navigation_rss -> { supportActionBar?.title = getString(R.string.rss) supportFragmentManager.beginTransaction() - .replace(R.id.fr_content, RssListFragment(), FRAGMENT_TAG) - .commit() + .replace(R.id.fr_content, RssListFragment(), FRAGMENT_TAG) + .commit() } + R.id.navigation_filter -> { supportActionBar?.title = getString(R.string.filter) supportFragmentManager.beginTransaction() - .replace(R.id.fr_content, FilterListFragment(), FRAGMENT_TAG) - .commit() + .replace(R.id.fr_content, FilterListFragment(), FRAGMENT_TAG) + .commit() } } } @@ -354,8 +357,8 @@ class TopActivity : }) val color = getThemeColor(R.attr.colorPrimary) - val searchAutoComplete = searchView!! - .findViewById(androidx.appcompat.R.id.search_src_text) as SearchView.SearchAutoComplete + val searchAutoComplete: TextView = searchView!! + .findViewById(androidx.appcompat.R.id.search_src_text) searchAutoComplete.setTextColor(color) searchAutoComplete.setHintTextColor(color) @@ -375,13 +378,13 @@ class TopActivity : } - override fun onShowcaseDismissed(materialShowcaseView: MaterialShowcaseView) { - if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { - goToFeedSearch() - } + override fun onShowcaseDismissed(materialShowcaseView: MaterialShowcaseView) { + if (lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)) { + goToFeedSearch() } - }) - .show() + } + }) + .show() } } return true @@ -449,7 +452,9 @@ class TopActivity : private fun changeTab(position: Int) { when (position) { - PreferenceHelper.LAUNCH_CURATION -> navigationView.selectedItemId = R.id.navigation_curation + PreferenceHelper.LAUNCH_CURATION -> navigationView.selectedItemId = + R.id.navigation_curation + PreferenceHelper.LAUNCH_RSS -> navigationView.selectedItemId = R.id.navigation_rss } } @@ -470,7 +475,7 @@ class TopActivity : closeRateDialogActionCreator.run() } } - .show() + .show() } private fun goToGooglePlay() {