Skip to content

Commit

Permalink
Fix lint error
Browse files Browse the repository at this point in the history
SearchView.SearchAutoComplete can only be accessed from within the same library group prefix
  • Loading branch information
phicdy committed Jul 7, 2024
1 parent e12582d commit 8440833
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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))
}
Expand All @@ -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) {
Expand All @@ -118,16 +124,17 @@ 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)
return false
}
})
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
Expand All @@ -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 -> {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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))
}
Expand All @@ -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) {
Expand All @@ -87,16 +92,19 @@ 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)
return false
}
})
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
Expand All @@ -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 -> {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,17 +23,18 @@ 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
private const val TAG_FRAGMENT = "TAG_FRAGMENT"
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
Expand All @@ -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 {
Expand All @@ -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))
}
Expand All @@ -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) {
Expand All @@ -106,16 +111,19 @@ 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)
return false
}
})
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
Expand All @@ -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 -> {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -260,6 +266,6 @@ class FeedSearchActivity : AppCompatActivity(), FeedSearchView, CoroutineScope {
@ActivityScoped
@Provides
fun provideFeedSearchView(@ActivityContext activity: Context): FeedSearchView =
activity as FeedSearchView
activity as FeedSearchView
}
}
Loading

0 comments on commit 8440833

Please sign in to comment.