Diario: nueva pantalla con frases vistas filtrable por anime
Spinner 'Todos los animes' + los que tienen frases vistas; lista con frase+anime y menu contextual copiar/compartir (patron Favoritos). Entrada 'Diario' en el menu principal.
This commit is contained in:
1 parent
13aac8f959
commit
ea9795403d
4 files changed
+161
No files matched your search
@@ -25,6 +25,7 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".FavsActivity" android:exported="false"/>
|
||||
<activity android:name=".DiaryActivity" android:exported="false"/>
|
||||
<activity android:name=".AnimesSelActivity" android:exported="false"/>
|
||||
<activity android:name=".OptsActivity" android:exported="false"/>
|
||||
<activity android:name=".AboutActivity" android:exported="false"/>
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.ContextMenu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.SimpleAdapter
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.jkanetwork.st.frasesdeanime.databinding.ActivityDiaryBinding
|
||||
|
||||
/**
|
||||
* Diario (rediseño 2026-10): todas las frases ya vistas, filtrables por anime
|
||||
* con un desplegable. Patrón de FavsActivity (lista simple_2 + menú contextual).
|
||||
*/
|
||||
class DiaryActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityDiaryBinding
|
||||
|
||||
/* IDs de frase que hay en la lista, en el mismo orden que el adapter */
|
||||
private var listIDFrases: List<Int> = emptyList()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityDiaryBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
applySystemBarsInsets(binding.root)
|
||||
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
supportActionBar?.setTitle(R.string.menu_diario)
|
||||
|
||||
val db = SQLiteHelper(applicationContext)
|
||||
|
||||
/* Desplegable: "Todos los animes" + los que tienen frases vistas.
|
||||
La posición 0 es "todos"; las demás llevan el IDAnime en tag. */
|
||||
val animesWithSeen = LinkedHashMap<Int, String>() // IDAnime -> Name (orden alfabético)
|
||||
db.getSeenFrases().forEach { idf ->
|
||||
val ida = db.getIDAnimeFromIDF(idf)
|
||||
if (ida > 0 && !animesWithSeen.containsKey(ida)) {
|
||||
val name = db.getAnimeFromIDF(idf)
|
||||
if (name != "...") animesWithSeen[ida] = name
|
||||
}
|
||||
}
|
||||
val spinnerNames = mutableListOf(getString(R.string.diario_todos))
|
||||
val spinnerIds = mutableListOf<Int?>(null)
|
||||
animesWithSeen.entries.sortedBy { it.value.lowercase() }.forEach { (ida, name) ->
|
||||
spinnerIds.add(ida)
|
||||
spinnerNames.add(name)
|
||||
}
|
||||
|
||||
val spinnerAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, spinnerNames)
|
||||
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
binding.spinnerAnime.adapter = spinnerAdapter
|
||||
|
||||
binding.spinnerAnime.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
loadList(db, spinnerIds[position])
|
||||
}
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
||||
}
|
||||
|
||||
/* Estado del filtro restaurado tras recrear la activity (giro, etc.).
|
||||
OJO: registrar el listener después del primer layout dispara onItemSelected
|
||||
solo a veces; la carga inicial se hace aquí explícitamente. */
|
||||
val savedSel = if (savedInstanceState?.containsKey("spinner") == true) savedInstanceState.getInt("spinner") else 0
|
||||
if (savedSel in spinnerNames.indices) binding.spinnerAnime.setSelection(savedSel, false)
|
||||
loadList(db, spinnerIds[if (savedSel in spinnerIds.indices) savedSel else 0])
|
||||
|
||||
registerForContextMenu(binding.viewList)
|
||||
}
|
||||
|
||||
/** Rellena la lista con las frases vistas del anime indicado (null = todos) */
|
||||
private fun loadList(db: SQLiteHelper, idAnime: Int?) {
|
||||
listIDFrases = db.getSeenFrases(idAnime)
|
||||
val data = ArrayList<HashMap<String, String>>()
|
||||
for (idf in listIDFrases) {
|
||||
val item = HashMap<String, String>()
|
||||
item["sentence"] = db.getSentenceFromIDF(idf)
|
||||
item["anime"] = db.getAnimeFromIDF(idf)
|
||||
data.add(item)
|
||||
}
|
||||
binding.viewList.adapter = SimpleAdapter(this, data, android.R.layout.simple_list_item_2,
|
||||
arrayOf("sentence", "anime"), intArrayOf(android.R.id.text1, android.R.id.text2))
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putInt("spinner", binding.spinnerAnime.selectedItemPosition)
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(menu: ContextMenu, v: View, menuInfo: ContextMenu.ContextMenuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo)
|
||||
menuInflater.inflate(R.menu.menu_diarysentence, menu)
|
||||
}
|
||||
|
||||
/** Flecha Atrás del ActionBar */
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
finish()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
val info = item.menuInfo as AdapterView.AdapterContextMenuInfo
|
||||
if (info.position !in listIDFrases.indices) return false
|
||||
val db = SQLiteHelper(applicationContext)
|
||||
val idf = listIDFrases[info.position]
|
||||
val sentence = db.getSentenceFromIDF(idf)
|
||||
val anime = db.getAnimeFromIDF(idf)
|
||||
val shared = "$sentence ($anime) \n ${getString(R.string.sharefrom)}"
|
||||
|
||||
when (item.itemId) {
|
||||
R.id.copy -> {
|
||||
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
clipboard.setPrimaryClip(ClipData.newPlainText("Sentence", shared))
|
||||
toast("Copiado al portapapeles")
|
||||
return true
|
||||
}
|
||||
R.id.share -> {
|
||||
share(shared)
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Diario: desplegable de filtro por anime + lista de frases vistas.
|
||||
Basado en activity_list.xml (Favoritos) con Spinner añadido arriba. -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner_anime"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_margin="12dp" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/view_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Menú contextual de una frase del Diario (como Favoritos sin "borrar fav") -->
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:id="@+id/copy"
|
||||
android:title="Copiar" />
|
||||
|
||||
<item android:id="@+id/share"
|
||||
android:title="Compartir" />
|
||||
</menu>
|
||||
Reference in new issue
Block a user