Skip to content

Commit 39450e0

Browse files
authored
Merge pull request libre-tube#7225 from Bnyro/master
feat: add full local mode option to home screen
2 parents 677d7de + 3cca462 commit 39450e0

4 files changed

Lines changed: 101 additions & 23 deletions

File tree

app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,11 @@ class MainActivity : BaseActivity() {
108108
startActivity(noInternetIntent)
109109
finish()
110110
return
111-
} else if (PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, "").isEmpty()) {
111+
}
112+
113+
val isAppConfigured = PreferenceHelper.getBoolean(PreferenceKeys.LOCAL_FEED_EXTRACTION, false) ||
114+
PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, "").isNotEmpty()
115+
if (!isAppConfigured) {
112116
val welcomeIntent = Intent(this, WelcomeActivity::class.java)
113117
startActivity(welcomeIntent)
114118
finish()

app/src/main/java/com/github/libretube/ui/activities/WelcomeActivity.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.widget.Toast
77
import androidx.activity.result.contract.ActivityResultContracts
88
import androidx.activity.viewModels
99
import androidx.core.view.isGone
10+
import androidx.core.view.isVisible
1011
import com.github.libretube.databinding.ActivityWelcomeBinding
1112
import com.github.libretube.ui.adapters.InstancesAdapter
1213
import com.github.libretube.ui.base.BaseActivity
@@ -36,18 +37,25 @@ class WelcomeActivity : BaseActivity() {
3637
binding.instancesRecycler.adapter = adapter
3738

3839
binding.okay.setOnClickListener {
39-
viewModel.saveSelectedInstance()
40+
viewModel.onConfirmSettings()
4041
}
4142

4243
binding.restore.setOnClickListener {
4344
restoreFilePicker.launch(BackupRestoreSettings.JSON)
4445
}
4546

46-
viewModel.uiState.observe(this) { (selectedIndex, instances, error, navigateToMain) ->
47-
binding.okay.isEnabled = selectedIndex != null
47+
binding.operationModeGroup.addOnButtonCheckedListener { _, checkedId, isChecked ->
48+
if (checkedId == binding.fullLocalModeToggleGroupButton.id) viewModel.setFullLocalModeEnabled(isChecked)
49+
}
50+
51+
viewModel.uiState.observe(this) { (fullLocalMode, selectedIndex, instances, error, navigateToMain) ->
52+
binding.okay.isEnabled = fullLocalMode || selectedIndex != null
4853
binding.progress.isGone = instances.isNotEmpty()
4954

50-
adapter.submitList(instances)
55+
binding.instancesContainer.isVisible = !fullLocalMode
56+
binding.localModeInfoContainer.isVisible = fullLocalMode
57+
58+
if (!fullLocalMode) adapter.submitList(instances)
5159

5260
error?.let {
5361
Toast.makeText(this, it, Toast.LENGTH_LONG).show()

app/src/main/java/com/github/libretube/ui/models/WelcomeViewModel.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,23 @@ class WelcomeViewModel(
4646
}
4747
}
4848

49+
fun setFullLocalModeEnabled(enabled: Boolean) {
50+
savedStateHandle[UI_STATE] = _uiState.value.copy(fullLocalMode = enabled)
51+
}
52+
4953
fun setSelectedInstanceIndex(index: Int) {
5054
savedStateHandle[UI_STATE] = _uiState.value.copy(selectedInstanceIndex = index)
5155
}
5256

53-
fun saveSelectedInstance() {
57+
fun onConfirmSettings() {
58+
val fullLocalMode = _uiState.value.fullLocalMode
5459
val selectedInstanceIndex = _uiState.value.selectedInstanceIndex
55-
if (selectedInstanceIndex == null) {
60+
61+
if (fullLocalMode) {
62+
PreferenceHelper.putBoolean(PreferenceKeys.FULL_LOCAL_MODE, true)
63+
PreferenceHelper.putBoolean(PreferenceKeys.LOCAL_FEED_EXTRACTION, true)
64+
refreshAndNavigate()
65+
} else if (selectedInstanceIndex == null) {
5666
savedStateHandle[UI_STATE] = _uiState.value.copy(error = R.string.choose_instance)
5767
} else {
5868
PreferenceHelper.putString(
@@ -91,6 +101,7 @@ class WelcomeViewModel(
91101

92102
@Parcelize
93103
data class UiState(
104+
val fullLocalMode: Boolean = false,
94105
val selectedInstanceIndex: Int? = null,
95106
val instances: List<PipedInstance> = emptyList(),
96107
@StringRes val error: Int? = null,

app/src/main/res/layout/activity_welcome.xml

Lines changed: 71 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@
4545
android:text="@string/welcome"
4646
android:textSize="18sp" />
4747

48-
<TextView
49-
android:layout_width="match_parent"
50-
android:layout_height="wrap_content"
51-
android:layout_gravity="center"
52-
android:layout_marginHorizontal="10dp"
53-
android:text="@string/choose_instance_long" />
54-
5548
</LinearLayout>
5649

5750
<com.google.android.material.appbar.MaterialToolbar
@@ -65,17 +58,79 @@
6558

6659
</com.google.android.material.appbar.AppBarLayout>
6760

68-
<androidx.recyclerview.widget.RecyclerView
69-
android:id="@+id/instances_recycler"
61+
<LinearLayout
62+
app:layout_behavior="@string/appbar_scrolling_view_behavior"
7063
android:layout_width="match_parent"
7164
android:layout_height="wrap_content"
72-
android:clipToPadding="false"
73-
android:fadeScrollbars="false"
74-
android:paddingBottom="70dp"
75-
android:scrollbars="vertical"
76-
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
77-
app:layout_behavior="@string/appbar_scrolling_view_behavior"
78-
tools:listitem="@layout/instance_row" />
65+
android:orientation="vertical">
66+
67+
<com.google.android.material.button.MaterialButtonToggleGroup
68+
android:id="@+id/operation_mode_group"
69+
app:selectionRequired="true"
70+
app:singleSelection="true"
71+
app:checkedButton="@+id/piped_toggle_group_button"
72+
android:layout_width="wrap_content"
73+
android:layout_height="wrap_content"
74+
android:layout_marginBottom="10dp">
75+
76+
<com.google.android.material.button.MaterialButton
77+
android:id="@+id/piped_toggle_group_button"
78+
style="?attr/materialButtonOutlinedStyle"
79+
android:layout_width="match_parent"
80+
android:layout_height="wrap_content"
81+
android:text="@string/piped" />
82+
83+
<com.google.android.material.button.MaterialButton
84+
android:id="@+id/full_local_mode_toggle_group_button"
85+
style="?attr/materialButtonOutlinedStyle"
86+
android:layout_width="match_parent"
87+
android:layout_height="wrap_content"
88+
android:text="@string/full_local_mode" />
89+
90+
</com.google.android.material.button.MaterialButtonToggleGroup>
91+
92+
<LinearLayout
93+
android:id="@+id/instances_container"
94+
android:layout_width="match_parent"
95+
android:layout_height="wrap_content"
96+
android:orientation="vertical">
97+
98+
<TextView
99+
android:layout_width="match_parent"
100+
android:layout_height="wrap_content"
101+
android:layout_gravity="center"
102+
android:layout_marginHorizontal="10dp"
103+
android:layout_marginBottom="10dp"
104+
android:text="@string/choose_instance_long" />
105+
106+
<androidx.recyclerview.widget.RecyclerView
107+
android:id="@+id/instances_recycler"
108+
android:layout_width="match_parent"
109+
android:layout_height="wrap_content"
110+
android:clipToPadding="false"
111+
android:fadeScrollbars="false"
112+
android:paddingBottom="70dp"
113+
android:scrollbars="vertical"
114+
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
115+
tools:listitem="@layout/instance_row" />
116+
117+
</LinearLayout>
118+
119+
<LinearLayout
120+
android:visibility="gone"
121+
android:id="@+id/local_mode_info_container"
122+
android:layout_width="match_parent"
123+
android:layout_height="wrap_content"
124+
android:orientation="vertical"
125+
android:paddingHorizontal="10dp">
126+
127+
<TextView
128+
android:layout_width="match_parent"
129+
android:layout_height="wrap_content"
130+
android:text="@string/full_local_mode_desc" />
131+
132+
</LinearLayout>
133+
</LinearLayout>
79134

80135
<FrameLayout
81136
android:id="@+id/progress"

0 commit comments

Comments
 (0)