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)
|
startActivity(noInternetIntent)
|
||||||
finish()
|
finish()
|
||||||
return
|
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)
|
val welcomeIntent = Intent(this, WelcomeActivity::class.java)
|
||||||
startActivity(welcomeIntent)
|
startActivity(welcomeIntent)
|
||||||
finish()
|
finish()
|
||||||
|
@ -7,6 +7,7 @@ import android.widget.Toast
|
|||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import com.github.libretube.databinding.ActivityWelcomeBinding
|
import com.github.libretube.databinding.ActivityWelcomeBinding
|
||||||
import com.github.libretube.ui.adapters.InstancesAdapter
|
import com.github.libretube.ui.adapters.InstancesAdapter
|
||||||
import com.github.libretube.ui.base.BaseActivity
|
import com.github.libretube.ui.base.BaseActivity
|
||||||
@ -36,18 +37,25 @@ class WelcomeActivity : BaseActivity() {
|
|||||||
binding.instancesRecycler.adapter = adapter
|
binding.instancesRecycler.adapter = adapter
|
||||||
|
|
||||||
binding.okay.setOnClickListener {
|
binding.okay.setOnClickListener {
|
||||||
viewModel.saveSelectedInstance()
|
viewModel.onConfirmSettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.restore.setOnClickListener {
|
binding.restore.setOnClickListener {
|
||||||
restoreFilePicker.launch(BackupRestoreSettings.JSON)
|
restoreFilePicker.launch(BackupRestoreSettings.JSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.uiState.observe(this) { (selectedIndex, instances, error, navigateToMain) ->
|
binding.operationModeGroup.addOnButtonCheckedListener { _, checkedId, isChecked ->
|
||||||
binding.okay.isEnabled = selectedIndex != null
|
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()
|
binding.progress.isGone = instances.isNotEmpty()
|
||||||
|
|
||||||
adapter.submitList(instances)
|
binding.instancesContainer.isVisible = !fullLocalMode
|
||||||
|
binding.localModeInfoContainer.isVisible = fullLocalMode
|
||||||
|
|
||||||
|
if (!fullLocalMode) adapter.submitList(instances)
|
||||||
|
|
||||||
error?.let {
|
error?.let {
|
||||||
Toast.makeText(this, it, Toast.LENGTH_LONG).show()
|
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) {
|
fun setSelectedInstanceIndex(index: Int) {
|
||||||
savedStateHandle[UI_STATE] = _uiState.value.copy(selectedInstanceIndex = index)
|
savedStateHandle[UI_STATE] = _uiState.value.copy(selectedInstanceIndex = index)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveSelectedInstance() {
|
fun onConfirmSettings() {
|
||||||
|
val fullLocalMode = _uiState.value.fullLocalMode
|
||||||
val selectedInstanceIndex = _uiState.value.selectedInstanceIndex
|
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)
|
savedStateHandle[UI_STATE] = _uiState.value.copy(error = R.string.choose_instance)
|
||||||
} else {
|
} else {
|
||||||
PreferenceHelper.putString(
|
PreferenceHelper.putString(
|
||||||
@ -91,6 +101,7 @@ class WelcomeViewModel(
|
|||||||
|
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class UiState(
|
data class UiState(
|
||||||
|
val fullLocalMode: Boolean = false,
|
||||||
val selectedInstanceIndex: Int? = null,
|
val selectedInstanceIndex: Int? = null,
|
||||||
val instances: List<PipedInstance> = emptyList(),
|
val instances: List<PipedInstance> = emptyList(),
|
||||||
@StringRes val error: Int? = null,
|
@StringRes val error: Int? = null,
|
||||||
|
@ -45,13 +45,6 @@
|
|||||||
android:text="@string/welcome"
|
android:text="@string/welcome"
|
||||||
android:textSize="18sp" />
|
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>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
@ -65,17 +58,79 @@
|
|||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<LinearLayout
|
||||||
android:id="@+id/instances_recycler"
|
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:clipToPadding="false"
|
android:orientation="vertical">
|
||||||
android:fadeScrollbars="false"
|
|
||||||
android:paddingBottom="70dp"
|
<com.google.android.material.button.MaterialButtonToggleGroup
|
||||||
android:scrollbars="vertical"
|
android:id="@+id/operation_mode_group"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
app:selectionRequired="true"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
app:singleSelection="true"
|
||||||
tools:listitem="@layout/instance_row" />
|
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"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:fadeScrollbars="false"
|
||||||
|
android:paddingBottom="70dp"
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
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
|
<FrameLayout
|
||||||
android:id="@+id/progress"
|
android:id="@+id/progress"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user