[skip ci] feat: new settings UI
This commit is contained in:
parent
91d1d2cf1d
commit
cd3bb20afd
11 changed files with 170 additions and 209 deletions
|
@ -1,8 +1,8 @@
|
|||
package ani.dantotsu.settings
|
||||
|
||||
import android.view.ViewGroup
|
||||
import ani.dantotsu.databinding.ItemSettingsBinding
|
||||
import ani.dantotsu.databinding.ItemSettingsSwitchBinding
|
||||
import java.lang.reflect.Array
|
||||
|
||||
data class Settings(
|
||||
val type: Int,
|
||||
|
@ -14,5 +14,6 @@ data class Settings(
|
|||
var isChecked : Boolean = false,
|
||||
val switch: ((isChecked:Boolean , view: ItemSettingsSwitchBinding ) -> Unit)? = null,
|
||||
val isVisible: Boolean = true,
|
||||
val isActivity: Boolean = false
|
||||
val isActivity: Boolean = false,
|
||||
val attach:((ViewGroup) -> Unit)? = null
|
||||
)
|
|
@ -63,6 +63,8 @@ class SettingsAdapter(private val settings: ArrayList<Settings>) :
|
|||
b.settingsLayout.visibility = if (settings.isVisible) View.VISIBLE else View.GONE
|
||||
b.settingsIconRight.visibility =
|
||||
if (settings.isActivity) View.VISIBLE else View.GONE
|
||||
b.attachView.visibility = if (settings.attach != null) View.VISIBLE else View.GONE
|
||||
settings.attach?.invoke(b.attachView)
|
||||
}
|
||||
|
||||
2 -> {
|
||||
|
|
|
@ -48,7 +48,13 @@ class SettingsExtensionsActivity: AppCompatActivity() {
|
|||
binding = ActivitySettingsExtensionsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
binding.apply {
|
||||
|
||||
settingsExtensionsLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = statusBarHeight
|
||||
bottomMargin = navBarHeight
|
||||
}
|
||||
extensionSettingsBack.setOnClickListener{
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
}
|
||||
fun setExtensionOutput(repoInventory: ViewGroup, type: MediaType) {
|
||||
repoInventory.removeAllViews()
|
||||
val prefName: PrefName? = when (type) {
|
||||
|
@ -70,7 +76,7 @@ class SettingsExtensionsActivity: AppCompatActivity() {
|
|||
LayoutInflater.from(repoInventory.context), repoInventory, true
|
||||
)
|
||||
view.repositoryItem.text =
|
||||
item.removePrefix("https://raw.githubusercontent.com")
|
||||
item.removePrefix("https://raw.githubusercontent.com/")
|
||||
view.repositoryItem.setOnClickListener {
|
||||
AlertDialog.Builder(context, R.style.MyPopup)
|
||||
.setTitle(R.string.rem_repository).setMessage(item)
|
||||
|
@ -107,7 +113,7 @@ class SettingsExtensionsActivity: AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
fun processUserInput(input: String, mediaType: MediaType) {
|
||||
fun processUserInput(input: String, mediaType: MediaType, view: ViewGroup) {
|
||||
val entry =
|
||||
if (input.endsWith("/") || input.endsWith("index.min.json")) input.substring(
|
||||
0,
|
||||
|
@ -120,7 +126,7 @@ class SettingsExtensionsActivity: AppCompatActivity() {
|
|||
CoroutineScope(Dispatchers.IO).launch {
|
||||
animeExtensionManager.findAvailableExtensions()
|
||||
}
|
||||
setExtensionOutput(animeRepoInventory, MediaType.ANIME)
|
||||
setExtensionOutput(view, MediaType.ANIME)
|
||||
}
|
||||
if (mediaType == MediaType.MANGA) {
|
||||
val manga =
|
||||
|
@ -129,17 +135,17 @@ class SettingsExtensionsActivity: AppCompatActivity() {
|
|||
CoroutineScope(Dispatchers.IO).launch {
|
||||
mangaExtensionManager.findAvailableExtensions()
|
||||
}
|
||||
setExtensionOutput(mangaRepoInventory, MediaType.MANGA)
|
||||
setExtensionOutput(view, MediaType.MANGA)
|
||||
}
|
||||
}
|
||||
|
||||
fun processEditorAction(dialog: AlertDialog, editText: EditText, mediaType: MediaType) {
|
||||
fun processEditorAction(dialog: AlertDialog, editText: EditText, mediaType: MediaType, view: ViewGroup) {
|
||||
editText.setOnEditorActionListener { textView, action, keyEvent ->
|
||||
if (action == EditorInfo.IME_ACTION_SEARCH || action == EditorInfo.IME_ACTION_DONE || (keyEvent?.action == KeyEvent.ACTION_UP && keyEvent.keyCode == KeyEvent.KEYCODE_ENTER)) {
|
||||
return@setOnEditorActionListener if (textView.text.isNullOrBlank()) {
|
||||
false
|
||||
} else {
|
||||
processUserInput(textView.text.toString(), mediaType)
|
||||
processUserInput(textView.text.toString(), mediaType, view)
|
||||
dialog.dismiss()
|
||||
true
|
||||
}
|
||||
|
@ -147,16 +153,14 @@ class SettingsExtensionsActivity: AppCompatActivity() {
|
|||
false
|
||||
}
|
||||
}
|
||||
settingsExtensionsLayout.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = statusBarHeight
|
||||
bottomMargin = navBarHeight
|
||||
}
|
||||
extensionSettingsBack.setOnClickListener{
|
||||
onBackPressedDispatcher.onBackPressed()
|
||||
}
|
||||
setExtensionOutput(animeRepoInventory, MediaType.ANIME)
|
||||
setExtensionOutput(mangaRepoInventory, MediaType.MANGA)
|
||||
animeAddRepository.setOnClickListener {
|
||||
settingsRecyclerView.adapter = SettingsAdapter(
|
||||
arrayListOf(
|
||||
Settings(
|
||||
type = 1,
|
||||
name = getString(R.string.anime_add_repository),
|
||||
desc = getString(R.string.anime_add_repository),
|
||||
icon = R.drawable.ic_github,
|
||||
onClick = {
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_user_agent, null)
|
||||
val editText =
|
||||
dialogView.findViewById<TextInputEditText>(R.id.userAgentTextBox).apply {
|
||||
|
@ -167,19 +171,28 @@ class SettingsExtensionsActivity: AppCompatActivity() {
|
|||
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
|
||||
if (!editText.text.isNullOrBlank()) processUserInput(
|
||||
editText.text.toString(),
|
||||
MediaType.ANIME
|
||||
MediaType.ANIME,
|
||||
it.attachView
|
||||
)
|
||||
dialog.dismiss()
|
||||
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}.create()
|
||||
|
||||
processEditorAction(alertDialog, editText, MediaType.ANIME)
|
||||
processEditorAction(alertDialog, editText, MediaType.ANIME, it.attachView)
|
||||
alertDialog.show()
|
||||
alertDialog.window?.setDimAmount(0.8f)
|
||||
},
|
||||
attach = { view ->
|
||||
setExtensionOutput(view, MediaType.ANIME)
|
||||
}
|
||||
|
||||
mangaAddRepository.setOnClickListener {
|
||||
),
|
||||
Settings(
|
||||
type = 1,
|
||||
name = getString(R.string.manga_add_repository),
|
||||
desc = getString(R.string.manga_add_repository),
|
||||
icon = R.drawable.ic_github,
|
||||
onClick = {
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_user_agent, null)
|
||||
val editText =
|
||||
dialogView.findViewById<TextInputEditText>(R.id.userAgentTextBox).apply {
|
||||
|
@ -190,21 +203,22 @@ class SettingsExtensionsActivity: AppCompatActivity() {
|
|||
.setPositiveButton(getString(R.string.ok)) { dialog, _ ->
|
||||
if (!editText.text.isNullOrBlank()) processUserInput(
|
||||
editText.text.toString(),
|
||||
MediaType.MANGA
|
||||
MediaType.MANGA,
|
||||
it.attachView
|
||||
)
|
||||
dialog.dismiss()
|
||||
}.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
}.create()
|
||||
|
||||
processEditorAction(alertDialog, editText, MediaType.MANGA)
|
||||
processEditorAction(alertDialog, editText, MediaType.MANGA, it.attachView)
|
||||
alertDialog.show()
|
||||
alertDialog.window?.setDimAmount(0.8f)
|
||||
},
|
||||
attach = { view ->
|
||||
setExtensionOutput(view, MediaType.MANGA)
|
||||
}
|
||||
}
|
||||
|
||||
binding.settingsRecyclerView.adapter = SettingsAdapter(
|
||||
arrayListOf(
|
||||
),
|
||||
Settings(
|
||||
type = 1,
|
||||
name = getString(R.string.user_agent),
|
||||
|
@ -269,9 +283,11 @@ class SettingsExtensionsActivity: AppCompatActivity() {
|
|||
)
|
||||
)
|
||||
)
|
||||
binding.settingsRecyclerView.apply {
|
||||
settingsRecyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
||||
setHasFixedSize(true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -63,7 +63,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
@ -135,7 +135,7 @@
|
|||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:alpha="0.58"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:text="@string/selected_dns" />
|
||||
|
@ -144,7 +144,7 @@
|
|||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:boxCornerRadiusBottomEnd="8dp"
|
||||
app:boxCornerRadiusBottomStart="8dp"
|
||||
|
|
|
@ -60,71 +60,6 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<Button
|
||||
android:layout_marginHorizontal="12dp"
|
||||
android:id="@+id/animeAddRepository"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:background="@drawable/ui_bg"
|
||||
android:backgroundTint="?attr/colorSecondary"
|
||||
android:backgroundTintMode="src_atop"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:insetTop="0dp"
|
||||
android:insetBottom="0dp"
|
||||
android:paddingHorizontal="31dp"
|
||||
android:text="@string/anime_add_repository"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
app:cornerRadius="0dp"
|
||||
app:icon="@drawable/ic_github"
|
||||
app:iconPadding="16dp"
|
||||
app:iconSize="24dp"
|
||||
app:iconTint="?attr/colorPrimary" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/animeRepoInventory"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="36dp"
|
||||
android:visibility="gone"
|
||||
tools:ignore="RtlSymmetry" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/mangaAddRepository"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:layout_marginHorizontal="12dp"
|
||||
android:background="@drawable/ui_bg"
|
||||
android:backgroundTint="?attr/colorSecondary"
|
||||
android:backgroundTintMode="src_atop"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:insetTop="0dp"
|
||||
android:insetBottom="0dp"
|
||||
android:paddingHorizontal="31dp"
|
||||
android:text="@string/manga_add_repository"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
app:cornerRadius="0dp"
|
||||
app:icon="@drawable/ic_github"
|
||||
app:iconPadding="16dp"
|
||||
app:iconSize="24dp"
|
||||
app:iconTint="?attr/colorPrimary" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/mangaRepoInventory"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="36dp"
|
||||
android:visibility="gone"
|
||||
tools:ignore="RtlSymmetry" />
|
||||
|
||||
<ani.dantotsu.FadingEdgeRecyclerView
|
||||
android:id="@+id/settingsRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
@ -139,7 +139,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginHorizontal="32dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
app:boxCornerRadiusBottomEnd="8dp"
|
||||
app:boxCornerRadiusBottomStart="8dp"
|
||||
app:boxCornerRadiusTopEnd="8dp"
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
android:id="@+id/repositoryItem"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/poppins_semi_bold"
|
||||
android:textSize="12sp"
|
||||
android:ellipsize="end"
|
||||
android:alpha="0.66"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
android:singleLine="true"
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
android:id="@+id/settingsIcon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_margin="24dp"
|
||||
android:layout_marginVertical="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
app:srcCompat="@drawable/ic_circle_add"
|
||||
app:tint="?attr/colorPrimary"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
@ -32,7 +33,7 @@
|
|||
android:fontFamily="@font/poppins_bold"
|
||||
android:text="@string/name"
|
||||
android:textColor="?attr/colorOnSurface"
|
||||
android:textSize="18sp" />
|
||||
android:textSize="16sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/settingsDesc"
|
||||
|
@ -42,13 +43,19 @@
|
|||
android:fontFamily="@font/poppins_semi_bold"
|
||||
android:text="@string/slogan"
|
||||
android:textColor="?attr/colorOnSurfaceVariant" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/attachView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
tools:ignore="RtlSymmetry" />
|
||||
</LinearLayout>
|
||||
<ImageView
|
||||
android:id="@+id/settingsIconRight"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
app:srcCompat="@drawable/ic_round_arrow_back_ios_new_24"
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
android:id="@+id/settingsIcon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_margin="24dp"
|
||||
android:layout_marginVertical="24dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
app:srcCompat="@drawable/ic_circle_add"
|
||||
app:tint="?attr/colorPrimary"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
@ -30,10 +31,9 @@
|
|||
android:layout_height="12dp"
|
||||
android:checked="false"
|
||||
android:elegantTextHeight="true"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:fontFamily="@font/poppins_bold"
|
||||
android:text="@string/name"
|
||||
android:textSize="18sp"
|
||||
android:textSize="16sp"
|
||||
android:textAlignment="viewStart"
|
||||
android:textColor="?attr/colorOnBackground"
|
||||
app:cornerRadius="0dp"
|
||||
|
@ -45,7 +45,7 @@
|
|||
android:id="@+id/settingsDesc"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="64dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:alpha="0.66"
|
||||
android:fontFamily="@font/poppins_semi_bold"
|
||||
android:text="@string/slogan"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue