mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 23:40:33 +05:30
Merge pull request #7225 from Bnyro/master
feat: add full local mode option to home screen
This commit is contained in:
commit
39450e0c1c
@ -108,7 +108,11 @@ class MainActivity : BaseActivity() {
|
||||
startActivity(noInternetIntent)
|
||||
finish()
|
||||
return
|
||||
} else if (PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, "").isEmpty()) {
|
||||
}
|
||||
|
||||
val isAppConfigured = PreferenceHelper.getBoolean(PreferenceKeys.LOCAL_FEED_EXTRACTION, false) ||
|
||||
PreferenceHelper.getString(PreferenceKeys.FETCH_INSTANCE, "").isNotEmpty()
|
||||
if (!isAppConfigured) {
|
||||
val welcomeIntent = Intent(this, WelcomeActivity::class.java)
|
||||
startActivity(welcomeIntent)
|
||||
finish()
|
||||
|
@ -7,6 +7,7 @@ import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isVisible
|
||||
import com.github.libretube.databinding.ActivityWelcomeBinding
|
||||
import com.github.libretube.ui.adapters.InstancesAdapter
|
||||
import com.github.libretube.ui.base.BaseActivity
|
||||
@ -36,18 +37,25 @@ class WelcomeActivity : BaseActivity() {
|
||||
binding.instancesRecycler.adapter = adapter
|
||||
|
||||
binding.okay.setOnClickListener {
|
||||
viewModel.saveSelectedInstance()
|
||||
viewModel.onConfirmSettings()
|
||||
}
|
||||
|
||||
binding.restore.setOnClickListener {
|
||||
restoreFilePicker.launch(BackupRestoreSettings.JSON)
|
||||
}
|
||||
|
||||
viewModel.uiState.observe(this) { (selectedIndex, instances, error, navigateToMain) ->
|
||||
binding.okay.isEnabled = selectedIndex != null
|
||||
binding.operationModeGroup.addOnButtonCheckedListener { _, checkedId, isChecked ->
|
||||
if (checkedId == binding.fullLocalModeToggleGroupButton.id) viewModel.setFullLocalModeEnabled(isChecked)
|
||||
}
|
||||
|
||||
viewModel.uiState.observe(this) { (fullLocalMode, selectedIndex, instances, error, navigateToMain) ->
|
||||
binding.okay.isEnabled = fullLocalMode || selectedIndex != null
|
||||
binding.progress.isGone = instances.isNotEmpty()
|
||||
|
||||
adapter.submitList(instances)
|
||||
binding.instancesContainer.isVisible = !fullLocalMode
|
||||
binding.localModeInfoContainer.isVisible = fullLocalMode
|
||||
|
||||
if (!fullLocalMode) adapter.submitList(instances)
|
||||
|
||||
error?.let {
|
||||
Toast.makeText(this, it, Toast.LENGTH_LONG).show()
|
||||
|
@ -46,13 +46,23 @@ class WelcomeViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun setFullLocalModeEnabled(enabled: Boolean) {
|
||||
savedStateHandle[UI_STATE] = _uiState.value.copy(fullLocalMode = enabled)
|
||||
}
|
||||
|
||||
fun setSelectedInstanceIndex(index: Int) {
|
||||
savedStateHandle[UI_STATE] = _uiState.value.copy(selectedInstanceIndex = index)
|
||||
}
|
||||
|
||||
fun saveSelectedInstance() {
|
||||
fun onConfirmSettings() {
|
||||
val fullLocalMode = _uiState.value.fullLocalMode
|
||||
val selectedInstanceIndex = _uiState.value.selectedInstanceIndex
|
||||
if (selectedInstanceIndex == null) {
|
||||
|
||||
if (fullLocalMode) {
|
||||
PreferenceHelper.putBoolean(PreferenceKeys.FULL_LOCAL_MODE, true)
|
||||
PreferenceHelper.putBoolean(PreferenceKeys.LOCAL_FEED_EXTRACTION, true)
|
||||
refreshAndNavigate()
|
||||
} else if (selectedInstanceIndex == null) {
|
||||
savedStateHandle[UI_STATE] = _uiState.value.copy(error = R.string.choose_instance)
|
||||
} else {
|
||||
PreferenceHelper.putString(
|
||||
@ -91,6 +101,7 @@ class WelcomeViewModel(
|
||||
|
||||
@Parcelize
|
||||
data class UiState(
|
||||
val fullLocalMode: Boolean = false,
|
||||
val selectedInstanceIndex: Int? = null,
|
||||
val instances: List<PipedInstance> = emptyList(),
|
||||
@StringRes val error: Int? = null,
|
||||
|
@ -45,13 +45,6 @@
|
||||
android:text="@string/welcome"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:text="@string/choose_instance_long" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
@ -65,6 +58,51 @@
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<LinearLayout
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||
android:id="@+id/operation_mode_group"
|
||||
app:selectionRequired="true"
|
||||
app:singleSelection="true"
|
||||
app:checkedButton="@+id/piped_toggle_group_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/piped_toggle_group_button"
|
||||
style="?attr/materialButtonOutlinedStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/piped" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/full_local_mode_toggle_group_button"
|
||||
style="?attr/materialButtonOutlinedStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/full_local_mode" />
|
||||
|
||||
</com.google.android.material.button.MaterialButtonToggleGroup>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/instances_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:text="@string/choose_instance_long" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/instances_recycler"
|
||||
android:layout_width="match_parent"
|
||||
@ -74,9 +112,26 @@
|
||||
android:paddingBottom="70dp"
|
||||
android:scrollbars="vertical"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:listitem="@layout/instance_row" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:visibility="gone"
|
||||
android:id="@+id/local_mode_info_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingHorizontal="10dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/full_local_mode_desc" />
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/progress"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
x
Reference in New Issue
Block a user