Migración a toolchain moderna y eliminación de Anko
Gradle 8.11.1, AGP 8.10.0, Kotlin 2.2.10, compile/targetSdk 36 (requisito Play 2026), minSdk 24 (exige ads 25.5.0), AdMob 25.5.0. anko-sqlite -> SQLiteOpenHelper nativo, commons -> helpers propios, layouts DSL -> XML + ViewBinding. Fixes: PendingIntent FLAG_IMMUTABLE, canal de notificaciones STN, ID de unidad correcto en RewardedAd.load, startService sobre receiver -> sendBroadcast, POST_NOTIFICATIONS en manifest.
This commit is contained in:
1 parent
8dd05334ec
commit
5a01a42cd7
18 files changed
+312
-279
No files matched your search
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
Aplicación Android (Kotlin) que muestra cada día una frase de una serie o película anime en tus notificaciones. Puedes revisar frases de días anteriores, marcarlas como favoritas y compartirlas.
|
Aplicación Android (Kotlin) que muestra cada día una frase de una serie o película anime en tus notificaciones. Puedes revisar frases de días anteriores, marcarlas como favoritas y compartirlas.
|
||||||
|
|
||||||
|
Publicada en Google Play: `com.jkanetwork.st.frasesdeanime`.
|
||||||
|
|
||||||
## Características
|
## Características
|
||||||
|
|
||||||
- Frase diaria en notificación, a la hora que configures (persistente opcional)
|
- Frase diaria en notificación, a la hora que configures (persistente opcional)
|
||||||
@@ -13,13 +15,15 @@ Aplicación Android (Kotlin) que muestra cada día una frase de una serie o pel
|
|||||||
|
|
||||||
## Compilar
|
## Compilar
|
||||||
|
|
||||||
- JDK 11 (Gradle 7.2 no arranca en JDK 17+)
|
- JDK 17
|
||||||
- Android Studio Arctic Fox o superior, o directamente `./gradlew assembleDebug`
|
- Android SDK con `platforms;android-36` y build-tools 34+
|
||||||
- compileSdk 31 / minSdk 21 / targetSdk 31
|
- `./gradlew assembleDebug` (o Android Studio)
|
||||||
|
|
||||||
|
Toolchain: Gradle 8.11.1 · AGP 8.10.0 · Kotlin 2.2.10 · compileSdk/targetSdk 36 · minSdk 24 (exigido por play-services-ads 25).
|
||||||
|
|
||||||
### Claves de AdMob
|
### Claves de AdMob
|
||||||
|
|
||||||
`app/src/main/res/values/admob.xml` está ignorado por git (contiene los IDs reales de AdMob). Sin ese fichero el build falla por recursos inexistentes. Créalo así:
|
`app/src/main/res/values/admob.xml` está ignorado por git (contiene los IDs reales). Sin ese fichero el build falla por recursos inexistentes. Créalo así:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
@@ -30,16 +34,26 @@ Aplicación Android (Kotlin) que muestra cada día una frase de una serie o pel
|
|||||||
</resources>
|
</resources>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- `admob_id` — ID de aplicación (meta-data del manifest, solo AdMob lo lee)
|
||||||
|
- `admob_videoid` — ID de unidad del anuncio recompensado (el que se pasa a `RewardedAd.load`)
|
||||||
|
- `admob_bannerid` — ID de unidad del banner (layout `activity_main.xml`)
|
||||||
|
|
||||||
|
### Firmar release
|
||||||
|
|
||||||
|
El APK release sale sin firmar (`app-release-unsigned.apk`); fírmalo con tu keystore (`apksigner` o el signing config de Android Studio). El `versionCode` se autoincrementa en cada build vía `app/versioncode.count`.
|
||||||
|
|
||||||
## Estructura del código
|
## Estructura del código
|
||||||
|
|
||||||
| Fichero | Responsabilidad |
|
| Fichero | Responsabilidad |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `MainActivity.kt` | Frase del día, favoritos, compartir, anuncio recompensado |
|
| `MainActivity.kt` | Frase del día, favoritos, compartir, anuncio recompensado |
|
||||||
| `AlarmNotif.kt` + `App.kt` (`putAlarm`) | Alarma diaria y notificación |
|
| `AlarmNotif.kt` + `App.kt` (`putAlarm`) | Alarma diaria y notificación (canal "STN") |
|
||||||
| `SQLiteHelper.kt` + `res/raw/loadsqlfile` | Base de datos de frases (SQL precargado) |
|
| `SQLiteHelper.kt` + `res/raw/loadsqlfile` | Base de datos de frases (SQL precargado) |
|
||||||
| `OptsActivity.kt` | Configuración (hora de notificación, notificación persistente) |
|
| `OptsActivity.kt` | Configuración (hora de notificación, notificación persistente) |
|
||||||
| `FavsActivity.kt` / `AnimesSelActivity.kt` / `AboutActivity.kt` | Favoritos, selección de animes, acerca de |
|
| `FavsActivity.kt` / `AnimesSelActivity.kt` / `AboutActivity.kt` | Favoritos, selección de animes, acerca de |
|
||||||
|
|
||||||
|
Sin Anko desde la migración de 2026: los helpers que lo sustituyen (`toast`, `share`, `browse`, `startActivity<T>`, `putAlarm`) viven en `App.kt`; la BD usa `SQLiteOpenHelper` nativo; los layouts DSL pasaron a XML + ViewBinding.
|
||||||
|
|
||||||
## Licencia
|
## Licencia
|
||||||
|
|
||||||
GPL. Ver `LICENSE.md` para detalles.
|
GPL. Ver `LICENSE.md` para detalles.
|
||||||
+17
-31
@@ -1,17 +1,16 @@
|
|||||||
def anko_version = '0.10.8'
|
plugins {
|
||||||
def kotlin_version = '1.5.20'
|
id 'com.android.application'
|
||||||
ext.kotlin_version = '1.5.20'
|
id 'kotlin-android'
|
||||||
|
}
|
||||||
apply plugin: 'com.android.application'
|
|
||||||
apply plugin: 'kotlin-android' // apply kotlin android plugin
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
|
namespace 'com.jkanetwork.st.frasesdeanime'
|
||||||
|
compileSdk 36
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.jkanetwork.st.frasesdeanime"
|
applicationId "com.jkanetwork.st.frasesdeanime"
|
||||||
minSdkVersion 21
|
minSdk 24
|
||||||
compileSdk 31
|
targetSdk 36
|
||||||
targetSdkVersion 31
|
|
||||||
// Sube automáticamente la build en cada compilacion
|
// Sube automáticamente la build en cada compilacion
|
||||||
def versionPropsFile = file('versioncode.count')
|
def versionPropsFile = file('versioncode.count')
|
||||||
def Properties versionProps = new Properties()
|
def Properties versionProps = new Properties()
|
||||||
@@ -21,7 +20,7 @@ android {
|
|||||||
versionProps.store(versionPropsFile.newWriter(), null)
|
versionProps.store(versionPropsFile.newWriter(), null)
|
||||||
// Fin de subir automáticamente la build en cada compilación
|
// Fin de subir automáticamente la build en cada compilación
|
||||||
versionCode code
|
versionCode code
|
||||||
versionName "1.4.6"
|
versionName "1.4.7"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -34,9 +33,13 @@ android {
|
|||||||
buildFeatures {
|
buildFeatures {
|
||||||
viewBinding true
|
viewBinding true
|
||||||
}
|
}
|
||||||
productFlavors {
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = '1.8'
|
||||||
}
|
}
|
||||||
namespace 'com.jkanetwork.st.frasesdeanime'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
@@ -44,24 +47,7 @@ sourceSets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation 'androidx.appcompat:appcompat:1.7.0'
|
||||||
implementation "org.jetbrains.anko:anko-sqlite:$anko_version"
|
|
||||||
implementation "org.jetbrains.anko:anko-commons:$anko_version"
|
|
||||||
// Anko Layouts
|
|
||||||
implementation "org.jetbrains.anko:anko-sdk25:$anko_version"
|
|
||||||
// sdk15, sdk19, sdk21, sdk23 are also available
|
|
||||||
implementation "org.jetbrains.anko:anko-appcompat-v7:$anko_version"
|
|
||||||
// Coroutine listeners for Anko Layouts
|
|
||||||
implementation "org.jetbrains.anko:anko-sdk25-coroutines:$anko_version"
|
|
||||||
implementation "org.jetbrains.anko:anko-appcompat-v7-coroutines:$anko_version"
|
|
||||||
implementation 'com.github.mirrajabi:kotlin-preferences-extensions:1.0.1'
|
|
||||||
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
|
||||||
|
|
||||||
implementation 'com.google.android.gms:play-services-ads:21.0.0'
|
implementation 'com.google.android.gms:play-services-ads:25.5.0'
|
||||||
//testImplementation 'junit:junit:4.12'
|
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
}
|
|
||||||
|
|
||||||
configurations.configureEach() {
|
|
||||||
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
||||||
}
|
}
|
||||||
@@ -3,11 +3,14 @@
|
|||||||
|
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
|
<!-- Notificaciones: permiso de runtime desde API 33, sin él no se muestra ninguna -->
|
||||||
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<!-- For Admob -->
|
<!-- For Admob -->
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
android:name=".App"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
|||||||
@@ -2,35 +2,20 @@ package com.jkanetwork.st.frasesdeanime
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.content.Context
|
import com.jkanetwork.st.frasesdeanime.databinding.ActivityAboutBinding
|
||||||
import android.widget.TextView
|
|
||||||
import android.widget.ImageView
|
|
||||||
import android.view.View
|
|
||||||
import android.graphics.Color
|
|
||||||
import android.graphics.drawable.ColorDrawable
|
|
||||||
import org.jetbrains.anko.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by kprkpr on 30/08/17.
|
* Created by kprkpr on 30/08/17.
|
||||||
|
* Layout DSL de Anko migrado a XML (activity_about.xml) + ViewBinding
|
||||||
*/
|
*/
|
||||||
class AboutActivity : AppCompatActivity(){
|
class AboutActivity : AppCompatActivity(){
|
||||||
|
|
||||||
|
private lateinit var binding: ActivityAboutBinding
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
binding = ActivityAboutBinding.inflate(layoutInflater)
|
||||||
//Anko DSL Layout
|
setContentView(binding.root)
|
||||||
verticalLayout {
|
|
||||||
textView{
|
|
||||||
text = "¡Gracias por usar Frases de Anime! \nIdea por Alba García y desarrollada por JKANetwork!"
|
|
||||||
textSize = 22f
|
|
||||||
textColor = Color.BLACK
|
|
||||||
textAlignment = View.TEXT_ALIGNMENT_CENTER
|
|
||||||
}.lparams(width=wrapContent, height=wrapContent){padding= dip(12)}
|
|
||||||
imageView{
|
|
||||||
setImageResource(R.drawable.cerebro)
|
|
||||||
}.lparams(width=matchParent, height=matchParent){}
|
|
||||||
background = ColorDrawable(Color.parseColor("#F8F2F2"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.jkanetwork.st.frasesdeanime
|
package com.jkanetwork.st.frasesdeanime
|
||||||
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -9,6 +10,7 @@ import java.util.Calendar
|
|||||||
import android.app.AlarmManager
|
import android.app.AlarmManager
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
|
import android.os.Build
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Help of: https://github.com/okwrtdsh/AlarmTest/blob/master/app/src/main/kotlin/com/github/okwrtdsh/alarmtest/AlarmBroadcastReceiver.kt
|
Help of: https://github.com/okwrtdsh/AlarmTest/blob/master/app/src/main/kotlin/com/github/okwrtdsh/alarmtest/AlarmBroadcastReceiver.kt
|
||||||
@@ -26,13 +28,21 @@ class AlarmNotif : BroadcastReceiver() {
|
|||||||
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||||
|
|
||||||
nm.cancel(1);
|
nm.cancel(1);
|
||||||
|
|
||||||
|
/* Canal de notificación: obligatorio desde API 26, sin él la notificación no se muestra */
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
val channel = NotificationChannel("STN", "Frase del día", NotificationManager.IMPORTANCE_DEFAULT)
|
||||||
|
channel.description = "Notificación diaria con la frase de anime"
|
||||||
|
nm.createNotificationChannel(channel)
|
||||||
|
}
|
||||||
|
|
||||||
val notificationBuilder = NotificationCompat.Builder(context, "STN")
|
val notificationBuilder = NotificationCompat.Builder(context, "STN")
|
||||||
.setContentTitle(anime)
|
.setContentTitle(anime)
|
||||||
.setStyle(NotificationCompat.BigTextStyle().bigText(frase))
|
.setStyle(NotificationCompat.BigTextStyle().bigText(frase))
|
||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
.setContentText(frase)
|
.setContentText(frase)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setContentIntent(PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), 0))
|
.setContentIntent(PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE))
|
||||||
|
|
||||||
var noti = notificationBuilder.build();
|
var noti = notificationBuilder.build();
|
||||||
|
|
||||||
@@ -48,7 +58,7 @@ class AlarmNotif : BroadcastReceiver() {
|
|||||||
time.set(Calendar.HOUR_OF_DAY, 0)
|
time.set(Calendar.HOUR_OF_DAY, 0)
|
||||||
time.set(Calendar.MINUTE, 0)
|
time.set(Calendar.MINUTE, 0)
|
||||||
time.set(Calendar.SECOND, 1)
|
time.set(Calendar.SECOND, 1)
|
||||||
val sender = PendingIntent.getBroadcast(context, 1, Intent(context, AlarmNotif::class.java), 0)
|
val sender = PendingIntent.getBroadcast(context, 1, Intent(context, AlarmNotif::class.java), PendingIntent.FLAG_IMMUTABLE)
|
||||||
alarmMgr.setRepeating(AlarmManager.RTC, time.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender) // Repeat every day
|
alarmMgr.setRepeating(AlarmManager.RTC, time.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender) // Repeat every day
|
||||||
}else{ /* For boot actions */
|
}else{ /* For boot actions */
|
||||||
putAlarm(context)
|
putAlarm(context)
|
||||||
|
|||||||
@@ -1,61 +1,34 @@
|
|||||||
package com.jkanetwork.st.frasesdeanime
|
package com.jkanetwork.st.frasesdeanime
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.view.View
|
import android.widget.CheckBox
|
||||||
import android.widget.SimpleAdapter
|
import com.jkanetwork.st.frasesdeanime.databinding.ActivityAnimesSelBinding
|
||||||
import android.widget.ListView
|
|
||||||
import android.widget.TextView
|
|
||||||
import android.widget.Button
|
|
||||||
import org.jetbrains.anko.*
|
|
||||||
import org.jetbrains.anko.support.v4.UI
|
|
||||||
import org.jetbrains.anko.support.v4.find
|
|
||||||
import android.widget.Toast
|
|
||||||
import android.util.Log
|
|
||||||
|
|
||||||
|
|
||||||
import androidx.core.content.ContextCompat.startActivity
|
|
||||||
import android.content.Intent
|
|
||||||
import android.widget.AdapterView
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by kprkpr on 25/07/17.
|
* Created by kprkpr on 25/07/17.
|
||||||
* Help: https://www.youtube.com/watch?v=x-M1L6tcsLo
|
* Help: https://www.youtube.com/watch?v=x-M1L6tcsLo
|
||||||
|
* Layout DSL de Anko migrado a XML (activity_animes_sel.xml) + ViewBinding
|
||||||
*/
|
*/
|
||||||
class AnimesSelActivity : AppCompatActivity(){
|
class AnimesSelActivity : AppCompatActivity(){
|
||||||
val act = this /* Activity Context */
|
private lateinit var binding: ActivityAnimesSelBinding
|
||||||
|
|
||||||
/* For DSL bind */
|
|
||||||
lateinit var view_list : ListView
|
|
||||||
lateinit var btn_exit : Button
|
|
||||||
lateinit var btn_sel : Button
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
var db = SQLiteHelper(applicationContext) //Database connection
|
binding = ActivityAnimesSelBinding.inflate(layoutInflater)
|
||||||
|
setContentView(binding.root)
|
||||||
/** Layout in DSL */
|
|
||||||
verticalLayout {
|
|
||||||
linearLayout {
|
|
||||||
btn_exit = button("Volver")
|
|
||||||
btn_sel = button("Seleccionar todos").lparams(width = matchParent)
|
|
||||||
}
|
|
||||||
view_list = listView {
|
|
||||||
}.lparams(width = matchParent, height = matchParent) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
val db = SQLiteHelper(applicationContext) //Database connection
|
||||||
|
|
||||||
if (db.getAllAnimeSel()){ //If all selected
|
if (db.getAllAnimeSel()){ //If all selected
|
||||||
btn_sel.setText("Deseleccionar todos")
|
binding.btnSel.setText("Deseleccionar todos")
|
||||||
}else{
|
}else{
|
||||||
btn_sel.setText("Seleccionar todos")
|
binding.btnSel.setText("Seleccionar todos")
|
||||||
}
|
}
|
||||||
|
|
||||||
//Load ids and Names
|
//Load ids and Names
|
||||||
val arrayIDs = db.getAllAnimeIDs()
|
val arrayIDs = db.getAllAnimeIDs()
|
||||||
var arrayNames = db.getAllAnimeNames()
|
val arrayNames = db.getAllAnimeNames()
|
||||||
val length = arrayIDs.size
|
val length = arrayIDs.size
|
||||||
|
|
||||||
//Init List of objets
|
//Init List of objets
|
||||||
@@ -66,34 +39,35 @@ class AnimesSelActivity : AppCompatActivity(){
|
|||||||
listNames += listOf(arrayNames[i])
|
listNames += listOf(arrayNames[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load adapter for view_list with an ANKO DSL style directy, and fill with data.
|
// Load adapter for view_list. CustomListAdapter class is in "CustomListAdapter.kt"
|
||||||
// CustomListAdapter class is in "CustomListAdapter.kt"
|
binding.viewList.adapter = CustomListAdapter<String>({ listNames }) {
|
||||||
view_list.adapter = CustomListAdapter<String>({ listNames }) {
|
index, listNames, view ->
|
||||||
index, listNames, view ->
|
val checkBox = CheckBox(this)
|
||||||
linearLayout {
|
checkBox.text = listNames[index]
|
||||||
checkBox {
|
checkBox.setOnClickListener { db.setAnimeSel(db.getIDAnimeFromName(listNames[index])) }
|
||||||
text = listNames[index]
|
checkBox.isChecked = listSel[index]
|
||||||
setOnClickListener { db.setAnimeSel(db.getIDAnimeFromName(listNames[index])) }
|
checkBox.textSize = 18f
|
||||||
setChecked(listSel[index])
|
checkBox.setPadding(0, dpToPx(6), 0, dpToPx(6))
|
||||||
textSize = 18f
|
checkBox
|
||||||
|
|
||||||
}.lparams(){topMargin = dip(6);bottomMargin = dip(6)}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btn_sel.setOnClickListener() {
|
binding.btnSel.setOnClickListener() {
|
||||||
db.setAllAnimeSel()
|
db.setAllAnimeSel()
|
||||||
restartActivity(act)
|
restartActivity(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
//"Return" to main
|
//"Return" to main
|
||||||
btn_exit.setOnClickListener() {
|
binding.btnExit.setOnClickListener() {
|
||||||
startActivity<MainActivity>()
|
startActivity<MainActivity>()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun dpToPx(dp: Int): Int =
|
||||||
|
(dp * resources.displayMetrics.density).toInt()
|
||||||
|
|
||||||
/** On back go to main */
|
/** On back go to main */
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
startActivity<MainActivity>()
|
startActivity<MainActivity>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,14 @@ package com.jkanetwork.st.frasesdeanime
|
|||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import android.app.AlarmManager
|
import android.app.AlarmManager
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.app.Notification
|
import android.widget.Toast
|
||||||
import android.app.NotificationManager
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by kprkpr on 18/07/17.
|
* Created by kprkpr on 18/07/17.
|
||||||
@@ -30,31 +29,54 @@ fun restartActivity(act: AppCompatActivity){
|
|||||||
act.startActivity(intent)
|
act.startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helpers que sustituyen a org.jetbrains.anko:anko-commons */
|
||||||
|
|
||||||
|
/** Toast corto, equivalente al toast() de Anko */
|
||||||
|
fun Context.toast(message: String) {
|
||||||
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Lanza el chooser de compartir, equivalente al share() de Anko */
|
||||||
|
fun Context.share(text: String) {
|
||||||
|
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||||
|
type = "text/plain"
|
||||||
|
putExtra(Intent.EXTRA_TEXT, text)
|
||||||
|
}
|
||||||
|
startActivity(Intent.createChooser(intent, null))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Abre una URL, equivalente al browse() de Anko */
|
||||||
|
fun Context.browse(url: String) {
|
||||||
|
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
|
||||||
|
}
|
||||||
|
|
||||||
|
/** inline reified para mantener la sintaxis startActivity<T>() de Anko */
|
||||||
|
inline fun <reified T : android.app.Activity> Context.startActivity() {
|
||||||
|
startActivity(Intent(this, T::class.java))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Call for putting alarm */
|
/* Call for putting alarm */
|
||||||
fun putAlarm(context: Context) {
|
fun putAlarm(context: Context) {
|
||||||
var P = Prefs(context)
|
val P = Prefs(context)
|
||||||
//val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
|
||||||
/* Common vars for alarm config */
|
/* Common vars for alarm config */
|
||||||
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||||
val sender = PendingIntent.getBroadcast(context, 1, Intent(context, AlarmNotif::class.java), 0)
|
val sender = PendingIntent.getBroadcast(context, 1, Intent(context, AlarmNotif::class.java), PendingIntent.FLAG_IMMUTABLE)
|
||||||
|
|
||||||
/* Cancel alarm first */
|
/* Cancel alarm first */
|
||||||
alarmMgr.cancel(sender)
|
alarmMgr.cancel(sender)
|
||||||
//nm.cancel(1);
|
|
||||||
|
|
||||||
|
val time = Calendar.getInstance()
|
||||||
var time = Calendar.getInstance()
|
|
||||||
if (P.getNotifOn()) {
|
if (P.getNotifOn()) {
|
||||||
if (P.getPersNotifOn()) { /* Persistent */
|
if (P.getPersNotifOn()) { /* Persistent */
|
||||||
var intent = Intent()
|
val intent = Intent()
|
||||||
intent.setAction("com.jkanetwork.st.frasesdeanime.notif")
|
intent.setAction("com.jkanetwork.st.frasesdeanime.notif")
|
||||||
context.sendBroadcast(intent)
|
context.sendBroadcast(intent)
|
||||||
|
|
||||||
}else{ /* At x hour every day */
|
}else{ /* At x hour every day */
|
||||||
|
|
||||||
/* Here set the alarm to one time a day in selected date. Default: 8AM */
|
/* Here set the alarm to one time a day in selected date. Default: 8AM */
|
||||||
/* Shedechule Alarm for tomorrow instead before now if alarm set to before. */
|
/* Schedule Alarm for tomorrow instead before now if alarm set to before. */
|
||||||
if (time.get(Calendar.HOUR_OF_DAY) > P.getHour() || ( time.get(Calendar.HOUR_OF_DAY) == P.getHour() && time.get(Calendar.MINUTE) > P.getMinute())) {
|
if (time.get(Calendar.HOUR_OF_DAY) > P.getHour() || ( time.get(Calendar.HOUR_OF_DAY) == P.getHour() && time.get(Calendar.MINUTE) > P.getMinute())) {
|
||||||
/* Add a day */
|
/* Add a day */
|
||||||
time.add(Calendar.DATE, 1)
|
time.add(Calendar.DATE, 1)
|
||||||
@@ -66,18 +88,12 @@ fun putAlarm(context: Context) {
|
|||||||
Log.d("STLOG (Next)", time.getTime().toString())
|
Log.d("STLOG (Next)", time.getTime().toString())
|
||||||
alarmMgr.setRepeating(AlarmManager.RTC, time.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender) // Repeat every day
|
alarmMgr.setRepeating(AlarmManager.RTC, time.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender) // Repeat every day
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class App : Application() {
|
class App : Application() {
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,41 +3,29 @@ package com.jkanetwork.st.frasesdeanime
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.content.Intent
|
|
||||||
import android.view.View
|
|
||||||
import android.widget.SimpleAdapter
|
|
||||||
import android.widget.ListView
|
|
||||||
import android.widget.TextView
|
|
||||||
import android.view.ContextMenu
|
import android.view.ContextMenu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import org.jetbrains.anko.*
|
import com.jkanetwork.st.frasesdeanime.databinding.ActivityListBinding
|
||||||
|
|
||||||
//import kotlinx.android.synthetic.main.activity_simplelistview.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by kprkpr on 25/07/17.
|
* Created by kprkpr on 25/07/17.
|
||||||
* Help: https://www.youtube.com/watch?v=x-M1L6tcsLo
|
* Help: https://www.youtube.com/watch?v=x-M1L6tcsLo
|
||||||
|
* Layout DSL de Anko migrado a XML (activity_list.xml) + ViewBinding
|
||||||
*/
|
*/
|
||||||
class FavsActivity : AppCompatActivity(){
|
class FavsActivity : AppCompatActivity(){
|
||||||
|
|
||||||
/* For DSL bind */
|
private lateinit var binding: ActivityListBinding
|
||||||
lateinit var view_list : ListView
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
binding = ActivityListBinding.inflate(layoutInflater)
|
||||||
/** Layout in DSL */
|
setContentView(binding.root)
|
||||||
verticalLayout {
|
|
||||||
view_list = listView {
|
|
||||||
}.lparams(width = matchParent, height = matchParent) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val data = ArrayList<HashMap<String,String>>()
|
val data = ArrayList<HashMap<String,String>>()
|
||||||
var db = SQLiteHelper(applicationContext)
|
val db = SQLiteHelper(applicationContext)
|
||||||
val listIDFrases = db.getAllIDFavs()
|
val listIDFrases = db.getAllIDFavs()
|
||||||
val length = listIDFrases.size
|
val length = listIDFrases.size
|
||||||
|
|
||||||
@@ -48,14 +36,14 @@ class FavsActivity : AppCompatActivity(){
|
|||||||
data.add(item)
|
data.add(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
view_list.adapter = SimpleAdapter(this,data,android.R.layout.simple_list_item_2,
|
binding.viewList.adapter = android.widget.SimpleAdapter(this,data,android.R.layout.simple_list_item_2,
|
||||||
arrayOf("sentence","anime"), intArrayOf(android.R.id.text1,android.R.id.text2))
|
arrayOf("sentence","anime"), intArrayOf(android.R.id.text1,android.R.id.text2))
|
||||||
|
|
||||||
registerForContextMenu(view_list)
|
registerForContextMenu(binding.viewList)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateContextMenu(menu: ContextMenu, v: View,
|
override fun onCreateContextMenu(menu: ContextMenu, v: android.view.View,
|
||||||
menuInfo: ContextMenu.ContextMenuInfo) {
|
menuInfo: ContextMenu.ContextMenuInfo) {
|
||||||
super.onCreateContextMenu(menu, v, menuInfo)
|
super.onCreateContextMenu(menu, v, menuInfo)
|
||||||
val inflater = getMenuInflater()
|
val inflater = getMenuInflater()
|
||||||
@@ -65,7 +53,7 @@ class FavsActivity : AppCompatActivity(){
|
|||||||
|
|
||||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||||
val info = item.getMenuInfo() as AdapterView.AdapterContextMenuInfo
|
val info = item.getMenuInfo() as AdapterView.AdapterContextMenuInfo
|
||||||
val obj = view_list.getItemAtPosition(info.position) as HashMap<String, String>
|
val obj = binding.viewList.getItemAtPosition(info.position) as HashMap<String, String>
|
||||||
|
|
||||||
when (item.getItemId()) {
|
when (item.getItemId()) {
|
||||||
R.id.copy -> {
|
R.id.copy -> {
|
||||||
@@ -90,5 +78,4 @@ class FavsActivity : AppCompatActivity(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,20 +2,18 @@ package com.jkanetwork.st.frasesdeanime
|
|||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import org.jetbrains.anko.*
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.content.Context
|
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.View
|
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.text.DateFormatSymbols
|
import java.text.DateFormatSymbols
|
||||||
import androidx.viewpager.widget.ViewPager
|
import android.widget.ImageView
|
||||||
|
import android.widget.LinearLayout
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
|
||||||
/* Ads */
|
/* Ads */
|
||||||
import com.google.android.gms.ads.AdRequest
|
import com.google.android.gms.ads.AdRequest
|
||||||
|
import com.google.android.gms.ads.MobileAds
|
||||||
import com.google.android.gms.ads.rewarded.RewardedAd;
|
import com.google.android.gms.ads.rewarded.RewardedAd;
|
||||||
|
|
||||||
|
|
||||||
@@ -47,7 +45,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(binding.root)
|
||||||
|
|
||||||
P = Prefs(applicationContext)
|
P = Prefs(applicationContext)
|
||||||
db = SQLiteHelper(applicationContext)
|
db = SQLiteHelper(applicationContext)
|
||||||
@@ -55,9 +53,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
/* Ads */
|
/* Ads */
|
||||||
// Initialize the Mobile Ads SDK.
|
// Initialize the Mobile Ads SDK.
|
||||||
|
MobileAds.initialize(this) { }
|
||||||
|
|
||||||
var adRequest = AdRequest.Builder().build()
|
// Cargar el anuncio recompensado con el ID de UNIDAD (videoid), no el de app
|
||||||
RewardedAd.load(this,this.getString(R.string.admob_id), adRequest, object : RewardedAdLoadCallback() {
|
val adRequest = AdRequest.Builder().build()
|
||||||
|
RewardedAd.load(this, this.getString(R.string.admob_videoid), adRequest, object : RewardedAdLoadCallback() {
|
||||||
override fun onAdFailedToLoad(adError: LoadAdError) {
|
override fun onAdFailedToLoad(adError: LoadAdError) {
|
||||||
rewardedAd = null
|
rewardedAd = null
|
||||||
}
|
}
|
||||||
@@ -67,34 +67,34 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
val extras = Bundle()
|
|
||||||
|
|
||||||
extras.putString("max_ad_content_rating", "PG") //Non adult ads
|
|
||||||
|
|
||||||
|
|
||||||
/* Check if first time or not, for welcoming user */
|
/* Check if first time or not, for welcoming user */
|
||||||
if (P.getFirstTime() == true){
|
if (P.getFirstTime() == true){
|
||||||
alert("Bienvenido a Frases de anime! Un lugar donde puedes descubrir las frases de tus animes favoritos, todos los días!\n" +
|
androidx.appcompat.app.AlertDialog.Builder(this)
|
||||||
"Selecciona de la siguiente lista los que más te gusten para empezar."){
|
.setMessage("Bienvenido a Frases de anime! Un lugar donde puedes descubrir las frases de tus animes favoritos, todos los días!\n" +
|
||||||
positiveButton("Empezemos") {startActivity<AnimesSelActivity>()}
|
"Selecciona de la siguiente lista los que más te gusten para empezar.")
|
||||||
}.show()
|
.setPositiveButton("Empezemos") { _, _ -> startActivity<AnimesSelActivity>() }
|
||||||
|
.show()
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
/* Check if no anime is selected */
|
/* Check if no anime is selected */
|
||||||
if (db.getCountAnimeSel() == 0) {
|
if (db.getCountAnimeSel() == 0) {
|
||||||
alert("No tienes ningún anime seleccionado, ¿Quieres seleccionarlos ahora?", "No hay animes seleccionados") {
|
androidx.appcompat.app.AlertDialog.Builder(this)
|
||||||
positiveButton("Si") { startActivity<AnimesSelActivity>() }
|
.setTitle("No hay animes seleccionados")
|
||||||
negativeButton("No") { }
|
.setMessage("No tienes ningún anime seleccionado, ¿Quieres seleccionarlos ahora?")
|
||||||
}.show()
|
.setPositiveButton("Si") { _, _ -> startActivity<AnimesSelActivity>() }
|
||||||
|
.setNegativeButton("No") { _, _ -> }
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//For "Vote us in Play Store"
|
//For "Vote us in Play Store"
|
||||||
if (P.getRateCountdown() == 0){
|
if (P.getRateCountdown() == 0){
|
||||||
alert("¿Te gusta la apliación? ¿Crees que la falta algo?"){
|
androidx.appcompat.app.AlertDialog.Builder(this)
|
||||||
positiveButton("Danos tu opinión") {browse("https://play.google.com/store/apps/details?id=com.jkanetwork.st.frasesdeanime")}
|
.setMessage("¿Te gusta la apliación? ¿Crees que la falta algo?")
|
||||||
negativeButton("Más tarde") { }
|
.setPositiveButton("Danos tu opinión") { _, _ -> browse("https://play.google.com/store/apps/details?id=com.jkanetwork.st.frasesdeanime") }
|
||||||
}.show()
|
.setNegativeButton("Más tarde") { _, _ -> }
|
||||||
|
.show()
|
||||||
P.setRateCountdown(); //To -1, if not..you know
|
P.setRateCountdown(); //To -1, if not..you know
|
||||||
}else{
|
}else{
|
||||||
P.setRateCountdown(); //Countdown one
|
P.setRateCountdown(); //Countdown one
|
||||||
@@ -121,33 +121,31 @@ class MainActivity : AppCompatActivity() {
|
|||||||
rewardedAd?.let { ad ->
|
rewardedAd?.let { ad ->
|
||||||
ad.show(this, OnUserEarnedRewardListener { rewardItem ->
|
ad.show(this, OnUserEarnedRewardListener { rewardItem ->
|
||||||
// Handle the reward. ANUNCIO VISTO CORRECTAMENTE.
|
// Handle the reward. ANUNCIO VISTO CORRECTAMENTE.
|
||||||
alert {
|
val gato = ImageView(this@MainActivity)
|
||||||
customView {
|
gato.setImageResource(R.drawable.gato)
|
||||||
linearLayout {
|
val padding = (4 * resources.displayMetrics.density).toInt()
|
||||||
imageView {
|
gato.setPadding(padding, padding, padding, padding)
|
||||||
imageResource = R.drawable.gato
|
androidx.appcompat.app.AlertDialog.Builder(this@MainActivity)
|
||||||
}.lparams(width = matchParent) {
|
.setView(gato)
|
||||||
margin = dip(4)
|
.setPositiveButton("Cambiar la frase") { _, _ ->
|
||||||
}
|
/* First remove sentence, then load a new one, and change data */
|
||||||
|
db.delSentence(yearS,monthS, dayS)
|
||||||
|
IDFraseS = db.getIDFrase(yearS,monthS, dayS)
|
||||||
|
changeData()
|
||||||
}
|
}
|
||||||
}
|
.show()
|
||||||
positiveButton("Cambiar la frase") {
|
|
||||||
/* First remove sentence, then load a new one, and change data */
|
|
||||||
db.delSentence(yearS,monthS, dayS)
|
|
||||||
IDFraseS = db.getIDFrase(yearS,monthS, dayS)
|
|
||||||
changeData()
|
|
||||||
}
|
|
||||||
}.show()
|
|
||||||
})
|
})
|
||||||
} ?: run {
|
} ?: run {
|
||||||
alert("Aún no hay un anuncio disponible, espere") {
|
androidx.appcompat.app.AlertDialog.Builder(this)
|
||||||
positiveButton("Ok") { }
|
.setMessage("Aún no hay un anuncio disponible, espere")
|
||||||
}.show()
|
.setPositiveButton("Ok") { _, _ -> }
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
}else{ // if (IDFraseS <= 0) {
|
}else{ // if (IDFraseS <= 0) {
|
||||||
alert("Aquí no puedes ver una frase aún, no sirve de nada pulsar el botón") {
|
androidx.appcompat.app.AlertDialog.Builder(this)
|
||||||
positiveButton("Ok") { }
|
.setMessage("Aquí no puedes ver una frase aún, no sirve de nada pulsar el botón")
|
||||||
}.show()
|
.setPositiveButton("Ok") { _, _ -> }
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,6 +211,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** "Close" app on back button */
|
/** "Close" app on back button */
|
||||||
|
@Deprecated("Deprecated in Java")
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
moveTaskToBack(true)
|
moveTaskToBack(true)
|
||||||
}
|
}
|
||||||
@@ -220,7 +219,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
/** It returns the month name */
|
/** It returns the month name */
|
||||||
fun getMonth(month: Int): String {
|
fun getMonth(month: Int): String {
|
||||||
val str = DateFormatSymbols().getMonths()[month - 1]
|
val str = DateFormatSymbols().getMonths()[month - 1]
|
||||||
return str.capitalize()
|
return str.replaceFirstChar { it.uppercase() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This function replaces texts of main activity to sentence using IDFraseS var
|
/** This function replaces texts of main activity to sentence using IDFraseS var
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package com.jkanetwork.st.frasesdeanime
|
|||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import android.content.Context
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import org.jetbrains.anko.*
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import android.content.BroadcastReceiver
|
import android.app.NotificationManager
|
||||||
import com.jkanetwork.st.frasesdeanime.databinding.ActivityOptsBinding
|
import com.jkanetwork.st.frasesdeanime.databinding.ActivityOptsBinding
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,11 +69,12 @@ class OptsActivity : AppCompatActivity(){
|
|||||||
P.setNotifOn(binding.chkAlarm.isChecked())
|
P.setNotifOn(binding.chkAlarm.isChecked())
|
||||||
P.setPersNotifOn(binding.chkPersistent.isChecked())
|
P.setPersNotifOn(binding.chkPersistent.isChecked())
|
||||||
|
|
||||||
val nm = applicationContext.notificationManager
|
val nm = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
nm.cancel(1); //Canel notif before service going on, for persistent notification problems
|
nm.cancel(1); //Cancel notif before service going on, for persistent notification problems
|
||||||
putAlarm(this)
|
putAlarm(this)
|
||||||
if (binding.chkPersistent.isChecked() && binding.chkAlarm.isChecked()) {
|
if (binding.chkPersistent.isChecked() && binding.chkAlarm.isChecked()) {
|
||||||
this.startService(Intent(this, AlarmNotif::class.java))
|
// Disparar la notificación persistente vía broadcast (AlarmNotif es un receiver, no un service)
|
||||||
|
sendBroadcast(Intent(this, AlarmNotif::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package com.jkanetwork.st.frasesdeanime
|
package com.jkanetwork.st.frasesdeanime
|
||||||
|
|
||||||
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.sqlite.SQLiteDatabase
|
import android.database.sqlite.SQLiteDatabase
|
||||||
import org.jetbrains.anko.db.*
|
import android.database.sqlite.SQLiteOpenHelper
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
@@ -11,15 +12,17 @@ import android.util.Log
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by kprkpr on 18/07/17.
|
* Created by kprkpr on 18/07/17.
|
||||||
|
* Migrado de anko-sqlite (ManagedSQLiteOpenHelper) a SQLiteOpenHelper nativo.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** ctx, DB.NAME, null, DB.Version */
|
/** ctx, DB.NAME, null, DB.Version */
|
||||||
class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite", null, 8) {
|
class SQLiteHelper(ctx: Context) : SQLiteOpenHelper(ctx, "otaku.sqlite", null, 8) {
|
||||||
val context = ctx
|
val context = ctx
|
||||||
val db = this.getWritableDatabase()
|
val db = this.getWritableDatabase()
|
||||||
|
|
||||||
// Hacer que los números al pasar a String tengan X digitos
|
// Hacer que los números al pasar a String tengan X digitos
|
||||||
fun Int.format(digits: Int) = java.lang.String.format("%0${digits}d", this)
|
fun Int.format(digits: Int) = java.lang.String.format("%0${digits}d", this)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private var instance: SQLiteHelper? = null
|
private var instance: SQLiteHelper? = null
|
||||||
|
|
||||||
@@ -38,13 +41,11 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||||
"TDay TEXT NOT NULL UNIQUE," +
|
"TDay TEXT NOT NULL UNIQUE," +
|
||||||
"IDFrase INTEGER)")
|
"IDFrase INTEGER)")
|
||||||
db.createTable("FRASESFAV", true,
|
db.execSQL("CREATE TABLE FRASESFAV (IDFrase INTEGER UNIQUE)")
|
||||||
"IDFrase" to INTEGER + UNIQUE)
|
db.execSQL("CREATE TABLE ANIMESON (IDAnime INTEGER UNIQUE)")
|
||||||
db.createTable("ANIMESON", true,
|
|
||||||
"IDAnime" to INTEGER + UNIQUE)
|
|
||||||
|
|
||||||
//Load animes and sentences
|
//Load animes and sentences
|
||||||
var queries: List<String> = readSqldata(R.raw.loadsqlfile).split(";\n");
|
val queries: List<String> = readSqldata(R.raw.loadsqlfile).split(";\n");
|
||||||
for (query in queries){
|
for (query in queries){
|
||||||
if (!query.isBlank())
|
if (!query.isBlank())
|
||||||
db.execSQL(query);
|
db.execSQL(query);
|
||||||
@@ -53,7 +54,7 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
|
|
||||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||||
// Here you can upgrade tables, as usual
|
// Here you can upgrade tables, as usual
|
||||||
var queries: List<String> = readSqldata(R.raw.loadsqlfile).split(";\n");
|
val queries: List<String> = readSqldata(R.raw.loadsqlfile).split(";\n");
|
||||||
for (query in queries){
|
for (query in queries){
|
||||||
if (!query.isBlank())
|
if (!query.isBlank())
|
||||||
db.execSQL(query);
|
db.execSQL(query);
|
||||||
@@ -86,11 +87,7 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
val query = db.rawQuery("SELECT IDFrase FROM FRASESFAV WHERE IDFrase = '$IDFrase'", null)
|
val query = db.rawQuery("SELECT IDFrase FROM FRASESFAV WHERE IDFrase = '$IDFrase'", null)
|
||||||
val res = query.getCount()
|
val res = query.getCount()
|
||||||
query.close()
|
query.close()
|
||||||
if (res > 0){
|
return res > 0
|
||||||
return true
|
|
||||||
}else{
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Changes the state of fav of a sentence
|
/** Changes the state of fav of a sentence
|
||||||
@@ -98,7 +95,9 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
*/
|
*/
|
||||||
fun setFav (IDFrase: Int) {
|
fun setFav (IDFrase: Int) {
|
||||||
if (getFav(IDFrase) == false){
|
if (getFav(IDFrase) == false){
|
||||||
db.insert("FRASESFAV","IDFrase" to IDFrase)
|
val values = ContentValues()
|
||||||
|
values.put("IDFrase", IDFrase)
|
||||||
|
db.insert("FRASESFAV", null, values)
|
||||||
}else{
|
}else{
|
||||||
db.execSQL("DELETE FROM FRASESFAV WHERE IDFrase='$IDFrase'")
|
db.execSQL("DELETE FROM FRASESFAV WHERE IDFrase='$IDFrase'")
|
||||||
}
|
}
|
||||||
@@ -125,8 +124,11 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getIDAnimeFromName (Name: String): Int {
|
fun getIDAnimeFromName (Name: String): Int {
|
||||||
var query = db.select("ANIMES", "IDAnime").whereArgs("Name = '$Name'")
|
val c = db.rawQuery("SELECT IDAnime FROM ANIMES WHERE Name = '$Name'", null)
|
||||||
return query.parseSingle(IntParser)
|
c.moveToFirst()
|
||||||
|
val ret = c.getInt(0)
|
||||||
|
c.close()
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -148,9 +150,10 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
try {
|
try {
|
||||||
query = db.rawQuery("SELECT IDFrase FROM FRASES WHERE IDAnime IN (SELECT IDAnime FROM ANIMESON) AND IDFrase NOT IN (SELECT IDFrase FROM FRASESVI) ORDER BY RANDOM() LIMIT 1", null)
|
query = db.rawQuery("SELECT IDFrase FROM FRASES WHERE IDAnime IN (SELECT IDAnime FROM ANIMESON) AND IDFrase NOT IN (SELECT IDFrase FROM FRASESVI) ORDER BY RANDOM() LIMIT 1", null)
|
||||||
query.moveToFirst()
|
query.moveToFirst()
|
||||||
db.insert("FRASESVI",
|
val values = ContentValues()
|
||||||
"TDay" to diaArg,
|
values.put("TDay", diaArg)
|
||||||
"IDFrase" to query.getString(0))
|
values.put("IDFrase", query.getString(0))
|
||||||
|
db.insert("FRASESVI", null, values)
|
||||||
val ret = query.getInt(0)
|
val ret = query.getInt(0)
|
||||||
query.close()
|
query.close()
|
||||||
return ret
|
return ret
|
||||||
@@ -170,20 +173,26 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getAllIDFavs(): Array<Int>{
|
fun getAllIDFavs(): Array<Int>{
|
||||||
var query = db.select("FRASESFAV", "IDFrase")
|
val c = db.rawQuery("SELECT IDFrase FROM FRASESFAV", null)
|
||||||
var list = query.parseList(IntParser)
|
val list = ArrayList<Int>()
|
||||||
|
while (c.moveToNext()) list.add(c.getInt(0))
|
||||||
|
c.close()
|
||||||
return list.toTypedArray()
|
return list.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllAnimeIDs(): Array<Int>{
|
fun getAllAnimeIDs(): Array<Int>{
|
||||||
var query = db.select("ANIMES", "IDAnime").orderBy("Name", SqlOrderDirection.ASC)
|
val c = db.rawQuery("SELECT IDAnime FROM ANIMES ORDER BY Name ASC", null)
|
||||||
var list = query.parseList(IntParser)
|
val list = ArrayList<Int>()
|
||||||
|
while (c.moveToNext()) list.add(c.getInt(0))
|
||||||
|
c.close()
|
||||||
return list.toTypedArray()
|
return list.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllAnimeNames(): Array<String>{
|
fun getAllAnimeNames(): Array<String>{
|
||||||
var query = db.select("ANIMES", "Name").orderBy("Name", SqlOrderDirection.ASC)
|
val c = db.rawQuery("SELECT Name FROM ANIMES ORDER BY Name ASC", null)
|
||||||
var list = query.parseList(StringParser)
|
val list = ArrayList<String>()
|
||||||
|
while (c.moveToNext()) list.add(c.getString(0))
|
||||||
|
c.close()
|
||||||
return list.toTypedArray()
|
return list.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,11 +201,7 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
val query = db.rawQuery("SELECT IDAnime FROM ANIMESON WHERE IDAnime = '$IDA'", null)
|
val query = db.rawQuery("SELECT IDAnime FROM ANIMESON WHERE IDAnime = '$IDA'", null)
|
||||||
val res = query.getCount()
|
val res = query.getCount()
|
||||||
query.close()
|
query.close()
|
||||||
if (res > 0){
|
return res > 0
|
||||||
return true
|
|
||||||
}else{
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Changes the state of a selected or not anime
|
/** Changes the state of a selected or not anime
|
||||||
@@ -204,7 +209,9 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
*/
|
*/
|
||||||
fun setAnimeSel (IDAnime: Int) {
|
fun setAnimeSel (IDAnime: Int) {
|
||||||
if (getAnimeSel(IDAnime) == false){
|
if (getAnimeSel(IDAnime) == false){
|
||||||
db.insert("ANIMESON","IDAnime" to IDAnime)
|
val values = ContentValues()
|
||||||
|
values.put("IDAnime", IDAnime)
|
||||||
|
db.insert("ANIMESON", null, values)
|
||||||
}else{
|
}else{
|
||||||
db.execSQL("DELETE FROM ANIMESON WHERE IDAnime='$IDAnime'")
|
db.execSQL("DELETE FROM ANIMESON WHERE IDAnime='$IDAnime'")
|
||||||
}
|
}
|
||||||
@@ -233,23 +240,24 @@ class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite",
|
|||||||
|
|
||||||
/** This funcion selects or desselects all animes from selected to show */
|
/** This funcion selects or desselects all animes from selected to show */
|
||||||
fun setAllAnimeSel(){
|
fun setAllAnimeSel(){
|
||||||
var selectAll = getAllAnimeSel(); //Know if anyone is select (true/false)
|
val selectAll = getAllAnimeSel(); //Know if anyone is select (true/false)
|
||||||
//First, unset all, and after that, select all if they were not before. (Why? Because if someone are select, inserting again will crash)
|
//First, unset all, and after that, select all if they were not before. (Why? Because if someone are select, inserting again will crash)
|
||||||
db.execSQL("DELETE FROM ANIMESON")
|
db.execSQL("DELETE FROM ANIMESON")
|
||||||
if (selectAll == false){ //Set all
|
if (selectAll == false){ //Set all
|
||||||
var animeIDs = getAllAnimeIDs()
|
val animeIDs = getAllAnimeIDs()
|
||||||
|
|
||||||
for (pos in animeIDs){
|
for (pos in animeIDs){
|
||||||
db.insert("ANIMESON",
|
val values = ContentValues()
|
||||||
"IDAnime" to animeIDs[pos-1]) //Pos is a count, arrays start at 0
|
values.put("IDAnime", animeIDs[pos-1]) //Pos is a count, arrays start at 0
|
||||||
|
db.insert("ANIMESON", null, values)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** It returns if all animes are selected or not */
|
/** It returns if all animes are selected or not */
|
||||||
fun getAllAnimeSel(): Boolean{
|
fun getAllAnimeSel(): Boolean{
|
||||||
var set = getCountAnimeSel();
|
val set = getCountAnimeSel();
|
||||||
var countanime = getAllAnimeIDs().size;
|
val countanime = getAllAnimeIDs().size;
|
||||||
if (set == countanime){
|
if (set == countanime){
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:background="#F8F2F2">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="¡Gracias por usar Frases de Anime! \nIdea por Alba García y desarrollada por JKANetwork!"
|
||||||
|
android:textSize="22sp"
|
||||||
|
android:textColor="#000000"
|
||||||
|
android:textAlignment="center"
|
||||||
|
android:padding="12dp" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:src="@drawable/cerebro"
|
||||||
|
android:contentDescription="Logo" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_exit"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Volver" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btn_sel"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Seleccionar todos" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/view_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Layout genérico de lista, sustituye al DSL verticalLayout{listView{}} de Anko -->
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/view_list"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -1,2 +1,2 @@
|
|||||||
#Sun Apr 07 19:54:23 CEST 2024
|
#Mon Oct 12 10:42:32 CEST 2026
|
||||||
VERSION_CODE=1354
|
VERSION_CODE=1361
|
||||||
+2
-35
@@ -1,38 +1,5 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
|
||||||
repositories {
|
|
||||||
jcenter()
|
|
||||||
maven { url 'https://jitpack.io' }
|
|
||||||
mavenCentral()
|
|
||||||
google()
|
|
||||||
}
|
|
||||||
dependencies {
|
|
||||||
classpath 'com.android.tools.build:gradle:7.0.4'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'org.jetbrains.kotlin.jvm' version '1.5.20'
|
id 'com.android.application' version '8.10.0' apply false
|
||||||
|
id 'org.jetbrains.kotlin.android' version '2.2.10' apply false
|
||||||
}
|
}
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
compileKotlin {
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
compileTestKotlin {
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
allprojects {
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
maven { url 'https://jitpack.io' }
|
|
||||||
jcenter()
|
|
||||||
google()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
@@ -1 +1,16 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dependencyResolutionManagement {
|
||||||
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
|
repositories {
|
||||||
|
google()
|
||||||
|
mavenCentral()
|
||||||
|
maven { url 'https://jitpack.io' }
|
||||||
|
}
|
||||||
|
}
|
||||||
include ':app'
|
include ':app'
|
||||||
Reference in new issue
Block a user