Changes to SourcesDialog and adapter

This commit is contained in:
Arty Bishop committed 2020-10-17 21:13:15 +01:00
1 parent 810fa5b85c
commit 68bae19b1a
6 files changed
+67 -105

No files matched your search

@@ -19,11 +19,10 @@
package com.rtbishop.look4sat.ui.adapters
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.widget.doOnTextChanged
import androidx.recyclerview.widget.RecyclerView
import com.rtbishop.look4sat.data.TleSource
import com.rtbishop.look4sat.databinding.ItemTleSourceBinding
@@ -43,11 +42,10 @@ class SourcesAdapter(private var sources: MutableList<TleSource>) :
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): TleSourceHolder {
val binding = ItemTleSourceBinding
.inflate(LayoutInflater.from(parent.context), parent, false)
return TleSourceHolder(binding.root, binding, TleSourceWatcher())
return TleSourceHolder(binding.root, binding)
}
override fun onBindViewHolder(holder: TleSourceHolder, position: Int) {
holder.textWatcher.updatePosition(position)
holder.bind(sources[position])
}
@@ -55,35 +53,16 @@ class SourcesAdapter(private var sources: MutableList<TleSource>) :
return sources.size
}
inner class TleSourceHolder(
itemView: View, val binding: ItemTleSourceBinding, val textWatcher: TleSourceWatcher
) :
inner class TleSourceHolder(itemView: View, val binding: ItemTleSourceBinding) :
RecyclerView.ViewHolder(itemView) {
fun bind(source: TleSource) {
binding.tleSourceUrl.setText(source.url)
binding.tleSourceUrl.addTextChangedListener(textWatcher)
binding.tleSourceBtnDel.setOnClickListener {
binding.tleSourceUrl.doOnTextChanged { text, _, _, _ -> source.url = text.toString() }
binding.tleSourceInputLayout.setEndIconOnClickListener {
sources.remove(source)
notifyItemRemoved(adapterPosition)
}
}
}
inner class TleSourceWatcher : TextWatcher {
private var position = 0
fun updatePosition(position: Int) {
this.position = position
}
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
sources[position].url = s.toString()
}
}
}
@@ -21,9 +21,9 @@ package com.rtbishop.look4sat.ui.fragments
import android.app.Dialog
import android.os.Bundle
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatDialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.rtbishop.look4sat.R
import com.rtbishop.look4sat.SharedViewModel
import com.rtbishop.look4sat.data.TleSource
import com.rtbishop.look4sat.databinding.DialogSourcesBinding
@@ -39,8 +39,8 @@ class SourcesDialog(sources: List<TleSource>, private val viewModel: SharedViewM
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val binding = DialogSourcesBinding.inflate(requireActivity().layoutInflater).apply {
tleSourcesRecycler.apply {
layoutManager = LinearLayoutManager(requireContext())
adapter = sourcesAdapter
layoutManager = LinearLayoutManager(requireContext())
}
tleSourceBtnAdd.setOnClickListener {
val tempSources = sourcesAdapter.getSources()
@@ -58,10 +58,7 @@ class SourcesDialog(sources: List<TleSource>, private val viewModel: SharedViewM
return Dialog(requireActivity()).apply {
setContentView(binding.root)
window?.setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
window?.setBackgroundDrawableResource(R.drawable.ic_launcher_background)
}
}
}
+47 -52
View File
@@ -2,55 +2,21 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tleSourcesDialog"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="4dp">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tleSourcesTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="10dp"
android:layout_marginTop="6dp"
android:text="@string/dialog_tle_sources"
android:textSize="17sp"
app:layout_constraintEnd_toStartOf="@+id/tleSourceBtnAdd"
app:layout_constraintHorizontal_bias="0.5"
android:textSize="16sp"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintStart_toStartOf="@+id/tleSourcesRecycler"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/tleSourceBtnAdd"
android:layout_width="36dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="10dp"
android:contentDescription="@string/placeholder"
app:layout_constraintBottom_toBottomOf="@+id/tleSourcesWarning"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/tleSourcesTitle"
app:layout_constraintTop_toTopOf="@+id/tleSourcesTitle"
app:srcCompat="@drawable/ic_add" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tleSourcesRecycler"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/tleSourcesBtnPos"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tleSourceBtnAdd"
app:layout_constraintVertical_chainStyle="packed">
</androidx.recyclerview.widget.RecyclerView>
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tleSourcesWarning"
android:layout_width="wrap_content"
@@ -58,29 +24,58 @@
android:layout_marginTop="4dp"
android:gravity="center"
android:text="@string/https_only"
android:textSize="17sp"
app:layout_constraintStart_toStartOf="@+id/tleSourcesTitle"
android:textSize="16sp"
app:layout_constraintStart_toStartOf="@+id/tleSourcesRecycler"
app:layout_constraintTop_toBottomOf="@+id/tleSourcesTitle" />
<com.google.android.material.textview.MaterialTextView
<ImageButton
android:id="@+id/tleSourceBtnAdd"
android:layout_width="48dp"
android:layout_height="0dp"
android:backgroundTint="@color/greySurface"
android:contentDescription="@string/placeholder"
android:src="@drawable/ic_add"
app:layout_constraintBottom_toBottomOf="@+id/tleSourcesWarning"
app:layout_constraintEnd_toEndOf="@+id/tleSourcesRecycler"
app:layout_constraintTop_toTopOf="@+id/tleSourcesTitle" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tleSourcesRecycler"
android:layout_width="266dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tleSourcesWarning">
</androidx.recyclerview.widget.RecyclerView>
<com.google.android.material.button.MaterialButton
android:id="@+id/tleSourcesBtnNeg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:backgroundTint="@color/greySurface"
android:text="@string/btn_cancel"
android:textSize="17sp"
android:textAllCaps="false"
android:textColor="@color/themeLight"
app:layout_constraintBaseline_toBaselineOf="@+id/tleSourcesBtnPos"
app:layout_constraintEnd_toStartOf="@+id/tleSourcesBtnPos"
app:layout_constraintHorizontal_chainStyle="spread_inside" />
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="@+id/tleSourcesRecycler" />
<com.google.android.material.textview.MaterialTextView
<com.google.android.material.button.MaterialButton
android:id="@+id/tleSourcesBtnPos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="@string/btn_ok"
android:textSize="17sp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:backgroundTint="@color/greySurface"
android:text="@string/btn_update"
android:textAllCaps="false"
android:textColor="@color/themeLight"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/tleSourceBtnAdd" />
app:layout_constraintEnd_toEndOf="@+id/tleSourcesRecycler"
app:layout_constraintTop_toBottomOf="@+id/tleSourcesRecycler" />
</androidx.constraintlayout.widget.ConstraintLayout>
+8 -19
View File
@@ -4,39 +4,28 @@
android:id="@+id/tleSourceItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp">
android:paddingTop="4dp"
android:paddingBottom="4dp">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tleSourceInputLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/tle_source"
app:endIconDrawable="@drawable/ic_map_sat"
app:endIconMode="custom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tleSourceBtnDel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<EditText
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tleSourceUrl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/tle_source"
android:importantForAutofill="no"
android:inputType="textUri" />
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/tleSourceBtnDel"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:contentDescription="@string/placeholder"
app:layout_constraintBottom_toBottomOf="@+id/tleSourceInputLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/tleSourceInputLayout"
app:layout_constraintTop_toTopOf="@+id/tleSourceInputLayout"
app:srcCompat="@android:drawable/ic_menu_close_clear_cancel" />
</androidx.constraintlayout.widget.ConstraintLayout>
+3 -2
View File
@@ -26,7 +26,7 @@
<string name="menu_prefs">Настройки</string>
<string name="menu_about">Инфо</string>
<string name="dialog_tle_sources">Управление источниками TLE</string>
<string name="dialog_tle_sources">Управление TLE</string>
<string name="dialog_entries_hint">ID / Имя</string>
<string name="pass_prefs_title">Настройки пролетов спутников</string>
@@ -100,8 +100,9 @@
<string name="btn_no">Нет</string>
<string name="btn_ok">OK</string>
<string name="btn_cancel">Отмена</string>
<string name="btn_update">Обновить</string>
<string name="tle_source">Источник TLE</string>
<string name="https_only">Используйте протокол HTTPS</string>
<string name="https_only">Используйте HTTPS</string>
<string name="sat_import">Импорт спутников</string>
</resources>
+1
View File
@@ -112,6 +112,7 @@
<string name="btn_no">No</string>
<string name="btn_ok">OK</string>
<string name="btn_cancel">Cancel</string>
<string name="btn_update">Update</string>
<string name="tle_source">TLE source</string>
<string name="https_only">Please use HTTPS URLs only</string>