Skip to content

Commit

Permalink
Merge pull request #37 from Y-E-P/task/Improve_searching_in_manifest_…
Browse files Browse the repository at this point in the history
…files

Task/improve searching in manifest files
  • Loading branch information
sdex authored Apr 17, 2023
2 parents 8026f6e + 205735c commit 43043e3
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 41 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ dependencies {
implementation "com.tomergoldst.android:tooltips:1.1.1"
implementation "net.dongliu:apk-parser:2.6.10"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4"
implementation "com.github.Y-E-P:BrowserFiP:1.0.5"

testImplementation "junit:junit:4.13.2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.Toolbar
import androidx.core.view.isVisible
import com.sdex.activityrunner.BuildConfig
import com.sdex.activityrunner.R
import com.sdex.activityrunner.commons.BaseActivity
import com.sdex.activityrunner.databinding.ActivityManifestViewerBinding
import com.sdex.activityrunner.db.cache.ApplicationModel
import com.sdex.activityrunner.preferences.AppPreferences
import com.sdex.activityrunner.util.IntentUtils
import com.sdex.activityrunner.util.UIUtils
import com.sdex.activityrunner.util.highlightjs.models.Language
import com.sdex.activityrunner.util.highlightjs.models.Theme
import com.yupo.browserfiplib.FiPSearchView
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

Expand Down Expand Up @@ -96,11 +98,48 @@ class ManifestViewerActivity : BaseActivity() {
}

viewModel.loadManifest(appPackageName)
setupFindInPage()
savedInstanceState?.let {
val isVisible = it.getBoolean(ARG_SHOULD_SHOW_FIP, false)
if(isVisible) showFindInPage() else hideFindInPage()
}
onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
isEnabled = false
if (binding.fip.isVisible) {
hideFindInPage()
isEnabled = true
} else {
onBackPressedDispatcher.onBackPressed()
}
}
})
}

private fun setupFindInPage() {
binding.fip.setupSearchComponent(binding.highlightView)
binding.fip.onNavigationClicked = {
if (it == FiPSearchView.ClickEvent.CLOSE) {
hideFindInPage()
}
}
}

private fun hideFindInPage() {
showToolbar()
binding.highlightView.clearMatches()
binding.fip.onActionViewCollapsed()
binding.fip.isVisible = false
}

private fun showFindInPage() {
hideToolbar()
binding.fip.onActionViewExpanded()
binding.fip.isVisible = true
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.manifest_viewer, menu)
configureSearchView(menu)
menu.findItem(R.id.action_line_numbers).isChecked = appPreferences.showLineNumbers
return super.onCreateOptionsMenu(menu)
}
Expand All @@ -117,6 +156,10 @@ class ManifestViewerActivity : BaseActivity() {
IntentUtils.openBrowser(this, url)
true
}
R.id.action_search -> {
showFindInPage()
false
}

R.id.action_line_numbers -> {
item.isChecked = !item.isChecked
Expand All @@ -138,52 +181,29 @@ class ManifestViewerActivity : BaseActivity() {

override fun onDestroy() {
super.onDestroy()
binding.fip.release()
binding.highlightView.setOnContentChangedListener(null)
}

private fun configureSearchView(menu: Menu) {
val searchItem = menu.findItem(R.id.action_search)
val searchView = searchItem.actionView as SearchView
// expand the view to the full width: https://stackoverflow.com/a/34050959/2894324
searchView.maxWidth = Int.MAX_VALUE
searchView.queryHint = getString(R.string.manifest_viewer_search_hint)
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
if (query.isNullOrEmpty()) {
binding.highlightView.clearMatches()
} else {
binding.highlightView.findAllAsync(query)
}
searchView.clearFocus()
return true
}
private fun hideToolbar() {
findViewById<Toolbar>(R.id.toolbar).isVisible = false
}

override fun onQueryTextChange(newText: String?): Boolean {
if (newText.isNullOrEmpty()) {
binding.highlightView.clearMatches()
}
return false
}
})
searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(item: MenuItem): Boolean {
UIUtils.setMenuItemsVisibility(menu, item, false)
return true
}
private fun showToolbar() {
findViewById<Toolbar>(R.id.toolbar).isVisible = true
}

override fun onMenuItemActionCollapse(item: MenuItem): Boolean {
binding.highlightView.clearMatches()
UIUtils.setMenuItemsVisibility(menu, true)
invalidateOptionsMenu()
return true
}
})
override fun onSaveInstanceState(outState: Bundle) {
outState.putBoolean(ARG_SHOULD_SHOW_FIP, binding.fip.isVisible)
super.onSaveInstanceState(outState)
}

companion object {

private const val ARG_PACKAGE_NAME = "arg_package_name"
private const val ARG_NAME = "arg_name"
private const val ARG_SHOULD_SHOW_FIP = "arg_should_show_fip"


fun start(context: Context, model: ApplicationModel) {
context.startActivity(Intent(context, ManifestViewerActivity::class.java).apply {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/background_fip.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<solid android:color="?colorSurface" />
</shape>
</item>
<item android:gravity="bottom">
<shape>
<size android:height="1dp" />
<solid android:color="@color/list_divider" />
</shape>
</item>
</layer-list>
20 changes: 19 additions & 1 deletion app/src/main/res/layout/activity_manifest_viewer.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".manifest.ManifestViewerActivity"
tools:ignore="ContentDescription">

<include layout="@layout/toolbar" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<include layout="@layout/toolbar" />

<com.yupo.browserfiplib.FiPSearchView
android:id="@+id/fip"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/background_fip"
android:visibility="gone"
app:fip_counter_matched_color="@color/md_theme_onSurface"
app:fip_divider_color="@color/list_divider"
app:fip_hint="@string/manifest_viewer_search_hint"
app:fip_text_color="@color/md_theme_onSurface" />

</FrameLayout>

<FrameLayout
android:layout_width="match_parent"
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/menu/manifest_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
android:id="@+id/action_search"
android:icon="@drawable/ic_search"
android:title="@string/manifest_viewer_search"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="always|collapseActionView" />
app:showAsAction="always" />

<item
android:id="@+id/action_export"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<color name="scrollbar_background">#2baaaaaa</color>
<color name="scrollbar_inactive_thumb">#9caaaaaa</color>

<color name="fip_inactive_color">#BDBDBD</color>
<color name="fip_active_color">#FFFFFF</color>
<color name="fip_active_selected">#FFFFFF</color>

<color name="md_theme_primary">#00629D</color>
<color name="md_theme_onPrimary">#003354</color>
<color name="md_theme_primaryContainer">#004A77</color>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<color name="scrollbar_background">#28000000</color>
<color name="scrollbar_inactive_thumb">#79000000</color>

<color name="fip_inactive_color">#BDBDBD</color>
<color name="fip_active_color">#000000</color>
<color name="fip_active_selected">#000000</color>

<color name="md_theme_primary">#00629D</color>
<color name="md_theme_onPrimary">#FFFFFF</color>
<color name="md_theme_primaryContainer">#CFE5FF</color>
Expand Down

0 comments on commit 43043e3

Please sign in to comment.