Skip to content

Commit 5564c00

Browse files
committed
refactor: new main navigation
1 parent 352ca26 commit 5564c00

30 files changed

Lines changed: 472 additions & 223 deletions

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ plugins {
1111
}
1212

1313
android {
14-
1514
compileSdk = 31
1615
compileOptions {
1716
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -136,6 +135,7 @@ dependencies {
136135

137136
implementation("com.getkeepsafe.taptargetview:taptargetview:1.13.3")
138137
implementation("com.github.topjohnwu.libsu:core:2.5.1")
138+
implementation("com.github.hadilq:live-event:1.3.0")
139139

140140
kapt("androidx.room:room-compiler:2.3.0")
141141
}

app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
android:name=".ui.params.list.KernelParamListActivity"
4444
android:label="@string/kernel_params"
4545
android:theme="@style/AppTheme" />
46-
<activity
47-
android:name=".ui.params.browse.KernelParamBrowserActivity"
48-
android:label="@string/browse_variables"
49-
android:theme="@style/AppTheme" />
5046
<activity
5147
android:name=".ui.params.user.ManageOnStartUpParamsActivity"
5248
android:label="@string/manage_parameters"

app/src/main/kotlin/com/androidvip/sysctlgui/di/PresentationModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import org.koin.androidx.viewmodel.dsl.viewModel
1212
import org.koin.dsl.module
1313

1414
internal val presentationModules = module {
15-
viewModel { BrowseParamsViewModel(get(), Dispatchers.IO) }
15+
viewModel { BrowseParamsViewModel(get(), Dispatchers.IO, get()) }
1616
viewModel { ListParamsViewModel(get()) }
1717
viewModel { UserParamsViewModel(get(), get(), get()) }
1818
viewModel { MainViewModel() }
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.androidvip.sysctlgui.helpers
22

33
enum class Actions {
4-
KernelParamsListActivity,
5-
KernelParamBrowserActivity,
6-
SettingsActivity,
4+
KernelParamsListFragment,
5+
KernelParamBrowserFragment,
6+
SettingsFragment,
77
ExportParams,
88
EditParam
99
}

app/src/main/kotlin/com/androidvip/sysctlgui/ui/StartActivity.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ import com.androidvip.sysctlgui.domain.usecase.PerformDatabaseMigrationUseCase
1717
import com.androidvip.sysctlgui.goAway
1818
import com.androidvip.sysctlgui.helpers.Actions
1919
import com.androidvip.sysctlgui.ui.main.MainActivity2
20-
import com.androidvip.sysctlgui.ui.params.browse.KernelParamBrowserActivity
2120
import com.androidvip.sysctlgui.ui.params.edit.EditKernelParamActivity
22-
import com.androidvip.sysctlgui.ui.params.list.KernelParamListActivity
2321
import com.androidvip.sysctlgui.ui.params.user.RemovableParamAdapter
24-
import com.androidvip.sysctlgui.ui.settings.SettingsActivity
2522
import com.topjohnwu.superuser.Shell
2623
import kotlinx.coroutines.Dispatchers
2724
import kotlinx.coroutines.delay
@@ -94,17 +91,17 @@ class StartActivity : AppCompatActivity() {
9491
}
9592

9693
private fun navigate() {
97-
val navigationIntent = when (this.intent.action) {
98-
Actions.KernelParamBrowserActivity.name -> {
99-
Intent(this, KernelParamBrowserActivity::class.java)
94+
when (this.intent.action) {
95+
Actions.KernelParamBrowserFragment.name -> {
96+
// TODO
10097
}
10198

102-
Actions.KernelParamsListActivity.name -> {
103-
Intent(this, KernelParamListActivity::class.java)
99+
Actions.KernelParamsListFragment.name -> {
100+
// TODO
104101
}
105102

106-
Actions.SettingsActivity.name -> {
107-
Intent(this, SettingsActivity::class.java)
103+
Actions.SettingsFragment.name -> {
104+
// TODO
108105
}
109106

110107
Actions.EditParam.name -> {
@@ -119,14 +116,13 @@ class StartActivity : AppCompatActivity() {
119116
RemovableParamAdapter.EXTRA_EDIT_SAVED_PARAM, false
120117
)
121118
)
119+
startActivity(this)
122120
}
123121
}
124122

125123
else -> {
126-
Intent(this, MainActivity2::class.java)
124+
startActivity(Intent(this, MainActivity2::class.java))
127125
}
128126
}
129-
130-
startActivity(navigationIntent)
131127
}
132128
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.androidvip.sysctlgui.ui.base
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.core.view.WindowCompat
7+
import androidx.viewbinding.ViewBinding
8+
9+
abstract class BaseActivity<Binding : ViewBinding>(
10+
open val bindingFactory: (LayoutInflater) -> Binding
11+
) : AppCompatActivity() {
12+
protected val binding: Binding by lazy { bindingFactory(layoutInflater) }
13+
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
WindowCompat.setDecorFitsSystemWindows(window, false)
17+
setContentView(binding.root)
18+
}
19+
}

app/src/main/kotlin/com/androidvip/sysctlgui/ui/base/BaseViewBindingFragment.kt renamed to app/src/main/kotlin/com/androidvip/sysctlgui/ui/base/BaseFragment.kt

File renamed without changes.

app/src/main/kotlin/com/androidvip/sysctlgui/ui/base/BaseSearchActivity.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.androidvip.sysctlgui.ui.base
22

33
import android.os.Bundle
4+
import android.view.LayoutInflater
45
import android.view.Menu
56
import android.widget.SearchView
6-
import androidx.appcompat.app.AppCompatActivity
77
import androidx.core.view.WindowCompat
8+
import androidx.viewbinding.ViewBinding
89
import com.androidvip.sysctlgui.R
9-
import java.util.*
1010

11-
abstract class BaseSearchActivity : AppCompatActivity() {
12-
protected val defaultLocale: Locale by lazy { Locale.getDefault() }
11+
abstract class BaseSearchActivity<Binding : ViewBinding>(
12+
override val bindingFactory: (LayoutInflater) -> Binding
13+
) : BaseActivity<Binding>(bindingFactory) {
1314
protected var searchExpression: String = ""
1415
private var searchView: SearchView? = null
1516

@@ -27,7 +28,7 @@ abstract class BaseSearchActivity : AppCompatActivity() {
2728

2829
abstract fun onQueryTextChanged()
2930

30-
fun setUpSearchView(menu: Menu?) {
31+
protected fun setUpSearchView(menu: Menu?) {
3132
searchView = (menu?.findItem(R.id.action_search)?.actionView as SearchView?)?.apply {
3233
setOnQueryTextListener(
3334
object :
@@ -51,11 +52,11 @@ abstract class BaseSearchActivity : AppCompatActivity() {
5152
}
5253
}
5354

54-
fun resetSearchExpression() {
55+
protected fun resetSearchExpression() {
5556
searchExpression = ""
5657
searchView?.setQuery("", false)
5758
}
5859

59-
val recyclerViewColumns: Int
60+
protected val recyclerViewColumns: Int
6061
get() = if (resources.getBoolean(R.bool.is_landscape)) 2 else 1
6162
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.androidvip.sysctlgui.ui.base
2+
3+
import android.os.Bundle
4+
import android.view.Menu
5+
import android.view.MenuInflater
6+
import android.widget.SearchView
7+
import androidx.viewbinding.ViewBinding
8+
import com.androidvip.sysctlgui.R
9+
10+
abstract class BaseSearchFragment<Binding : ViewBinding>(
11+
private val inflate: Inflate<Binding>
12+
) : BaseViewBindingFragment<Binding>(inflate::invoke) {
13+
protected var searchExpression: String = ""
14+
private var searchView: SearchView? = null
15+
16+
abstract fun onQueryTextChanged()
17+
18+
override fun onCreate(savedInstanceState: Bundle?) {
19+
super.onCreate(savedInstanceState)
20+
setHasOptionsMenu(true)
21+
}
22+
23+
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
24+
super.onCreateOptionsMenu(menu, inflater)
25+
26+
inflater.inflate(R.menu.menu_search, menu)
27+
setUpSearchView(menu)
28+
}
29+
30+
protected fun setUpSearchView(menu: Menu?) {
31+
searchView = (menu?.findItem(R.id.action_search)?.actionView as? SearchView)?.apply {
32+
setOnQueryTextListener(
33+
object :
34+
androidx.appcompat.widget.SearchView.OnQueryTextListener,
35+
SearchView.OnQueryTextListener {
36+
override fun onQueryTextSubmit(query: String?): Boolean {
37+
return true
38+
}
39+
40+
override fun onQueryTextChange(newText: String?): Boolean {
41+
searchExpression = newText.orEmpty().replace(".", "")
42+
43+
this@BaseSearchFragment.onQueryTextChanged()
44+
return true
45+
}
46+
})
47+
48+
// expand and show keyboard
49+
isIconifiedByDefault = false
50+
onActionViewExpanded()
51+
}
52+
}
53+
54+
protected fun resetSearchExpression() {
55+
searchExpression = ""
56+
searchView?.setQuery("", false)
57+
}
58+
}

app/src/main/kotlin/com/androidvip/sysctlgui/ui/export/ExportOptionsViewModel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class ExportOptionsViewModel(
7474
fun doWhenRestorePressed() = _viewEffect.postValue(ExportOptionsViewEffect.RestoreRuntimeParams)
7575

7676
fun importParams(stream: InputStream, fileExtension: String) = viewModelScope.launch {
77-
_viewState.postValue(currentViewState.copy(isLoading = true))
77+
_viewState.postValue(currentViewState.copyState(isLoading = true))
7878

7979
val postError: (Int) -> Unit = {
8080
_viewEffect.postValue(ExportOptionsViewEffect.ShowImportError(it))
@@ -101,11 +101,11 @@ class ExportOptionsViewModel(
101101
else -> postError(R.string.import_error)
102102
}
103103

104-
_viewState.postValue(currentViewState.copy(isLoading = false))
104+
_viewState.postValue(currentViewState.copyState(isLoading = false))
105105
}
106106

107107
fun exportParams(target: Uri, context: Context, backup: Boolean) = viewModelScope.launch {
108-
_viewState.postValue(currentViewState.copy(isLoading = true))
108+
_viewState.postValue(currentViewState.copyState(isLoading = true))
109109

110110
val postError: (Int) -> Unit = {
111111
_viewEffect.postValue(ExportOptionsViewEffect.ShowExportError(it))
@@ -130,7 +130,7 @@ class ExportOptionsViewModel(
130130
else -> postError(R.string.export_error)
131131
}
132132

133-
_viewState.postValue(currentViewState.copy(isLoading = false))
133+
_viewState.postValue(currentViewState.copyState(isLoading = false))
134134
}
135135

136136
private suspend fun exportParamsWithFileDescriptor(

0 commit comments

Comments
 (0)