WIP: migración 2024 sin commitear (AGP 7.0.4, Gradle 7.2, Kotlin 1.5.20, ViewBinding, AdMob 21) + README actualizado
Snapshot antes de migrar a toolchain moderna. Los CRLF vienen del trabajo original en Windows.
This commit is contained in:
1 parent
415a10c1af
commit
8dd05334ec
19 files changed
+2384
-2316
No files matched your search
@@ -1,21 +1,45 @@
|
||||
# Codigo fuente de "Frases de Anime"
|
||||
# Frases de Anime
|
||||
|
||||
Frases de Anime es una aplicacion para Android en la que todos los días tendrás una nueva frase de una serie Anime o película en tus notificaciones
|
||||
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.
|
||||
|
||||
Podrás ver frases anteriores, marcar como favoritos, o compartirlas con tus amigos
|
||||
## Características
|
||||
|
||||
## Requisitos para compilarla
|
||||
- Frase diaria en notificación, a la hora que configures (persistente opcional)
|
||||
- Navegación por días anteriores y vuelta al día actual
|
||||
- Favoritos con pantalla propia
|
||||
- Selección de animes de los que salir frases
|
||||
- Compartir la frase
|
||||
- Anuncio recompensado opcional para cambiar la frase del día
|
||||
|
||||
Android Studio 3.0+
|
||||
## Compilar
|
||||
|
||||
Kotlin
|
||||
- JDK 11 (Gradle 7.2 no arranca en JDK 17+)
|
||||
- Android Studio Arctic Fox o superior, o directamente `./gradlew assembleDebug`
|
||||
- compileSdk 31 / minSdk 21 / targetSdk 31
|
||||
|
||||
Anko (Debería descargarse automáticamente)
|
||||
### Claves de AdMob
|
||||
|
||||
## Problemas al compilar la aplicación
|
||||
`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í:
|
||||
|
||||
La aplicación puede dar problemas de compilación al faltar las claves API de Admob (No subidas porque son propias, evitamos un mal uso de la API). En res/strings.xml hay unas de ejemplo, deberían valer
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="admob_id">ca-app-pub-XXXX~XXXX</string>
|
||||
<string name="admob_videoid">ca-app-pub-XXXX/XXXX</string>
|
||||
<string name="admob_bannerid">ca-app-pub-XXXX/XXXX</string>
|
||||
</resources>
|
||||
```
|
||||
|
||||
## Estructura del código
|
||||
|
||||
| Fichero | Responsabilidad |
|
||||
|---|---|
|
||||
| `MainActivity.kt` | Frase del día, favoritos, compartir, anuncio recompensado |
|
||||
| `AlarmNotif.kt` + `App.kt` (`putAlarm`) | Alarma diaria y notificación |
|
||||
| `SQLiteHelper.kt` + `res/raw/loadsqlfile` | Base de datos de frases (SQL precargado) |
|
||||
| `OptsActivity.kt` | Configuración (hora de notificación, notificación persistente) |
|
||||
| `FavsActivity.kt` / `AnimesSelActivity.kt` / `AboutActivity.kt` | Favoritos, selección de animes, acerca de |
|
||||
|
||||
## Licencia
|
||||
|
||||
Mire el fichero LICENSE.md para detalles, usamos licencia GPL
|
||||
GPL. Ver `LICENSE.md` para detalles.
|
||||
+66
-68
@@ -1,69 +1,67 @@
|
||||
def anko_version = '0.10.8'
|
||||
def kotlin_version = '1.3.41'
|
||||
ext.kotlin_version = '1.3.41'
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android' // apply kotlin android plugin
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
defaultConfig {
|
||||
applicationId "com.jkanetwork.st.frasesdeanime"
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 28
|
||||
// Sube automáticamente la build en cada compilacion
|
||||
def versionPropsFile = file('versioncode.count')
|
||||
def Properties versionProps = new Properties()
|
||||
versionProps.load(new FileInputStream(versionPropsFile))
|
||||
def code = versionProps['VERSION_CODE'].toInteger() + 1
|
||||
versionProps['VERSION_CODE'] = code.toString()
|
||||
versionProps.store(versionPropsFile.newWriter(), null)
|
||||
// Fin de subir automáticamente la build en cada compilación
|
||||
versionCode code
|
||||
versionName "1.4.6"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
shrinkResources false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
productFlavors {
|
||||
}
|
||||
buildToolsVersion '28.0.3'
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
/*androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})*/
|
||||
//implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
//implementation 'com.android.support.constraint:constraint-layout:2.0.0-beta2'
|
||||
//implementation 'com.android.support:recyclerview-v7:28.0.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'
|
||||
|
||||
implementation 'com.google.android.gms:play-services-ads:18.1.1'
|
||||
//testImplementation 'junit:junit:4.12'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.41"
|
||||
}
|
||||
|
||||
configurations.all() {
|
||||
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
def anko_version = '0.10.8'
|
||||
def kotlin_version = '1.5.20'
|
||||
ext.kotlin_version = '1.5.20'
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android' // apply kotlin android plugin
|
||||
|
||||
android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.jkanetwork.st.frasesdeanime"
|
||||
minSdkVersion 21
|
||||
compileSdk 31
|
||||
targetSdkVersion 31
|
||||
// Sube automáticamente la build en cada compilacion
|
||||
def versionPropsFile = file('versioncode.count')
|
||||
def Properties versionProps = new Properties()
|
||||
versionProps.load(new FileInputStream(versionPropsFile))
|
||||
def code = versionProps['VERSION_CODE'].toInteger() + 1
|
||||
versionProps['VERSION_CODE'] = code.toString()
|
||||
versionProps.store(versionPropsFile.newWriter(), null)
|
||||
// Fin de subir automáticamente la build en cada compilación
|
||||
versionCode code
|
||||
versionName "1.4.6"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
shrinkResources false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
productFlavors {
|
||||
}
|
||||
namespace 'com.jkanetwork.st.frasesdeanime'
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
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'
|
||||
//testImplementation 'junit:junit:4.12'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
||||
configurations.configureEach() {
|
||||
resolutionStrategy.force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
@@ -1,40 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.jkanetwork.st.frasesdeanime">
|
||||
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<!-- For Admob -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".FavsActivity" />
|
||||
<activity android:name=".AnimesSelActivity" />
|
||||
<activity android:name=".OptsActivity" />
|
||||
<activity android:name=".AboutActivity" />
|
||||
<receiver android:process=":alarm" android:name=".AlarmNotif" android:enabled="true" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
<action android:name="com.jkanetwork.st.frasesdeanime.notif" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.ads.APPLICATION_ID"
|
||||
android:value="@string/admob_id"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<!-- For Admob -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".FavsActivity" android:exported="false"/>
|
||||
<activity android:name=".AnimesSelActivity" android:exported="false"/>
|
||||
<activity android:name=".OptsActivity" android:exported="false"/>
|
||||
<activity android:name=".AboutActivity" android:exported="false"/>
|
||||
<receiver android:process=":alarm" android:name=".AlarmNotif" android:exported="true" android:enabled="true" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"/>
|
||||
<action android:name="com.jkanetwork.st.frasesdeanime.notif" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.ads.APPLICATION_ID"
|
||||
android:value="@string/admob_id"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,36 +1,36 @@
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.content.Context
|
||||
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.
|
||||
*/
|
||||
class AboutActivity : AppCompatActivity(){
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
//Anko DSL Layout
|
||||
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"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.content.Context
|
||||
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.
|
||||
*/
|
||||
class AboutActivity : AppCompatActivity(){
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
//Anko DSL Layout
|
||||
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,58 +1,58 @@
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import java.util.Calendar
|
||||
import android.app.AlarmManager
|
||||
import androidx.core.app.NotificationCompat
|
||||
import android.app.PendingIntent
|
||||
|
||||
/*
|
||||
Help of: https://github.com/okwrtdsh/AlarmTest/blob/master/app/src/main/kotlin/com/github/okwrtdsh/alarmtest/AlarmBroadcastReceiver.kt
|
||||
|
||||
*/
|
||||
|
||||
class AlarmNotif : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent?) {
|
||||
var db = SQLiteHelper(context)
|
||||
var P = Prefs(context)
|
||||
val time = Calendar.getInstance()
|
||||
var frase = db.getSentenceFromIDF(db.getIDFraseHoy())
|
||||
var anime = db.getAnimeFromIDF(db.getIDFraseHoy())
|
||||
val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
|
||||
nm.cancel(1);
|
||||
val notificationBuilder = NotificationCompat.Builder(context, "STN")
|
||||
.setContentTitle(anime)
|
||||
.setStyle(NotificationCompat.BigTextStyle().bigText(frase))
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setContentText(frase)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setContentIntent(PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), 0))
|
||||
|
||||
var noti = notificationBuilder.build();
|
||||
|
||||
if (P.getPersNotifOn() == true) {
|
||||
noti.flags = Notification.FLAG_ONGOING_EVENT
|
||||
}
|
||||
|
||||
nm.notify(1,noti);
|
||||
|
||||
if (P.getPersNotifOn() == true) {
|
||||
/* Do notif change all days */
|
||||
time.add(Calendar.DATE, 1)
|
||||
time.set(Calendar.HOUR_OF_DAY, 0)
|
||||
time.set(Calendar.MINUTE, 0)
|
||||
time.set(Calendar.SECOND, 1)
|
||||
val sender = PendingIntent.getBroadcast(context, 1, Intent(context, AlarmNotif::class.java), 0)
|
||||
alarmMgr.setRepeating(AlarmManager.RTC, time.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender) // Repeat every day
|
||||
}else{ /* For boot actions */
|
||||
putAlarm(context)
|
||||
}
|
||||
}
|
||||
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import java.util.Calendar
|
||||
import android.app.AlarmManager
|
||||
import androidx.core.app.NotificationCompat
|
||||
import android.app.PendingIntent
|
||||
|
||||
/*
|
||||
Help of: https://github.com/okwrtdsh/AlarmTest/blob/master/app/src/main/kotlin/com/github/okwrtdsh/alarmtest/AlarmBroadcastReceiver.kt
|
||||
|
||||
*/
|
||||
|
||||
class AlarmNotif : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent?) {
|
||||
var db = SQLiteHelper(context)
|
||||
var P = Prefs(context)
|
||||
val time = Calendar.getInstance()
|
||||
var frase = db.getSentenceFromIDF(db.getIDFraseHoy())
|
||||
var anime = db.getAnimeFromIDF(db.getIDFraseHoy())
|
||||
val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
|
||||
nm.cancel(1);
|
||||
val notificationBuilder = NotificationCompat.Builder(context, "STN")
|
||||
.setContentTitle(anime)
|
||||
.setStyle(NotificationCompat.BigTextStyle().bigText(frase))
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.setContentText(frase)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setContentIntent(PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), 0))
|
||||
|
||||
var noti = notificationBuilder.build();
|
||||
|
||||
if (P.getPersNotifOn() == true) {
|
||||
noti.flags = Notification.FLAG_ONGOING_EVENT
|
||||
}
|
||||
|
||||
nm.notify(1,noti);
|
||||
|
||||
if (P.getPersNotifOn() == true) {
|
||||
/* Do notif change all days */
|
||||
time.add(Calendar.DATE, 1)
|
||||
time.set(Calendar.HOUR_OF_DAY, 0)
|
||||
time.set(Calendar.MINUTE, 0)
|
||||
time.set(Calendar.SECOND, 1)
|
||||
val sender = PendingIntent.getBroadcast(context, 1, Intent(context, AlarmNotif::class.java), 0)
|
||||
alarmMgr.setRepeating(AlarmManager.RTC, time.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender) // Repeat every day
|
||||
}else{ /* For boot actions */
|
||||
putAlarm(context)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,101 +1,101 @@
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import android.widget.SimpleAdapter
|
||||
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.
|
||||
* Help: https://www.youtube.com/watch?v=x-M1L6tcsLo
|
||||
*/
|
||||
class AnimesSelActivity : AppCompatActivity(){
|
||||
val act = this /* Activity Context */
|
||||
|
||||
/* For DSL bind */
|
||||
lateinit var view_list : ListView
|
||||
lateinit var btn_exit : Button
|
||||
lateinit var btn_sel : Button
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
var db = SQLiteHelper(applicationContext) //Database connection
|
||||
|
||||
/** 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) { }
|
||||
}
|
||||
|
||||
|
||||
if (db.getAllAnimeSel()){ //If all selected
|
||||
btn_sel.setText("Deseleccionar todos")
|
||||
}else{
|
||||
btn_sel.setText("Seleccionar todos")
|
||||
}
|
||||
|
||||
//Load ids and Names
|
||||
val arrayIDs = db.getAllAnimeIDs()
|
||||
var arrayNames = db.getAllAnimeNames()
|
||||
val length = arrayIDs.size
|
||||
|
||||
//Init List of objets
|
||||
var listSel: List<Boolean> = (emptyList())
|
||||
var listNames: List<String> = (emptyList())
|
||||
for (i in 0..length -1){ //Load selected for every one and create list names/selected
|
||||
listSel += listOf(db.getAnimeSel(arrayIDs[i]))
|
||||
listNames += listOf(arrayNames[i])
|
||||
}
|
||||
|
||||
// Load adapter for view_list with an ANKO DSL style directy, and fill with data.
|
||||
// CustomListAdapter class is in "CustomListAdapter.kt"
|
||||
view_list.adapter = CustomListAdapter<String>({ listNames }) {
|
||||
index, listNames, view ->
|
||||
linearLayout {
|
||||
checkBox {
|
||||
text = listNames[index]
|
||||
setOnClickListener { db.setAnimeSel(db.getIDAnimeFromName(listNames[index])) }
|
||||
setChecked(listSel[index])
|
||||
textSize = 18f
|
||||
|
||||
}.lparams(){topMargin = dip(6);bottomMargin = dip(6)}
|
||||
}
|
||||
}
|
||||
|
||||
btn_sel.setOnClickListener() {
|
||||
db.setAllAnimeSel()
|
||||
restartActivity(act)
|
||||
}
|
||||
|
||||
//"Return" to main
|
||||
btn_exit.setOnClickListener() {
|
||||
startActivity<MainActivity>()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** On back go to main */
|
||||
override fun onBackPressed() {
|
||||
startActivity<MainActivity>()
|
||||
}
|
||||
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import android.widget.SimpleAdapter
|
||||
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.
|
||||
* Help: https://www.youtube.com/watch?v=x-M1L6tcsLo
|
||||
*/
|
||||
class AnimesSelActivity : AppCompatActivity(){
|
||||
val act = this /* Activity Context */
|
||||
|
||||
/* For DSL bind */
|
||||
lateinit var view_list : ListView
|
||||
lateinit var btn_exit : Button
|
||||
lateinit var btn_sel : Button
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
var db = SQLiteHelper(applicationContext) //Database connection
|
||||
|
||||
/** 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) { }
|
||||
}
|
||||
|
||||
|
||||
if (db.getAllAnimeSel()){ //If all selected
|
||||
btn_sel.setText("Deseleccionar todos")
|
||||
}else{
|
||||
btn_sel.setText("Seleccionar todos")
|
||||
}
|
||||
|
||||
//Load ids and Names
|
||||
val arrayIDs = db.getAllAnimeIDs()
|
||||
var arrayNames = db.getAllAnimeNames()
|
||||
val length = arrayIDs.size
|
||||
|
||||
//Init List of objets
|
||||
var listSel: List<Boolean> = (emptyList())
|
||||
var listNames: List<String> = (emptyList())
|
||||
for (i in 0..length -1){ //Load selected for every one and create list names/selected
|
||||
listSel += listOf(db.getAnimeSel(arrayIDs[i]))
|
||||
listNames += listOf(arrayNames[i])
|
||||
}
|
||||
|
||||
// Load adapter for view_list with an ANKO DSL style directy, and fill with data.
|
||||
// CustomListAdapter class is in "CustomListAdapter.kt"
|
||||
view_list.adapter = CustomListAdapter<String>({ listNames }) {
|
||||
index, listNames, view ->
|
||||
linearLayout {
|
||||
checkBox {
|
||||
text = listNames[index]
|
||||
setOnClickListener { db.setAnimeSel(db.getIDAnimeFromName(listNames[index])) }
|
||||
setChecked(listSel[index])
|
||||
textSize = 18f
|
||||
|
||||
}.lparams(){topMargin = dip(6);bottomMargin = dip(6)}
|
||||
}
|
||||
}
|
||||
|
||||
btn_sel.setOnClickListener() {
|
||||
db.setAllAnimeSel()
|
||||
restartActivity(act)
|
||||
}
|
||||
|
||||
//"Return" to main
|
||||
btn_exit.setOnClickListener() {
|
||||
startActivity<MainActivity>()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** On back go to main */
|
||||
override fun onBackPressed() {
|
||||
startActivity<MainActivity>()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,84 +1,84 @@
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.app.PendingIntent
|
||||
import java.util.Calendar
|
||||
import android.app.AlarmManager
|
||||
import android.util.Log
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
|
||||
/**
|
||||
* Created by kprkpr on 18/07/17.
|
||||
* Here, functions for using in every part of app
|
||||
*/
|
||||
|
||||
|
||||
/** Restart activity without doing animations for refresh favs
|
||||
* @param act: Use "this.intent"
|
||||
* */
|
||||
fun restartActivity(act: AppCompatActivity){
|
||||
val intent = act.intent
|
||||
act.overridePendingTransition(0, 0)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
|
||||
act.finish()
|
||||
act.overridePendingTransition(0, 0)
|
||||
act.startActivity(intent)
|
||||
}
|
||||
|
||||
|
||||
/* Call for putting alarm */
|
||||
fun putAlarm(context: Context) {
|
||||
var P = Prefs(context)
|
||||
//val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
/* Common vars for alarm config */
|
||||
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
val sender = PendingIntent.getBroadcast(context, 1, Intent(context, AlarmNotif::class.java), 0)
|
||||
|
||||
/* Cancel alarm first */
|
||||
alarmMgr.cancel(sender)
|
||||
//nm.cancel(1);
|
||||
|
||||
|
||||
var time = Calendar.getInstance()
|
||||
if (P.getNotifOn()) {
|
||||
if (P.getPersNotifOn()) { /* Persistent */
|
||||
var intent = Intent()
|
||||
intent.setAction("com.jkanetwork.st.frasesdeanime.notif")
|
||||
context.sendBroadcast(intent)
|
||||
|
||||
}else{ /* At x hour every day */
|
||||
|
||||
/* 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. */
|
||||
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 */
|
||||
time.add(Calendar.DATE, 1)
|
||||
}
|
||||
|
||||
time.set(Calendar.HOUR_OF_DAY, P.getHour())
|
||||
time.set(Calendar.MINUTE, P.getMinute())
|
||||
time.set(Calendar.SECOND, 0)
|
||||
Log.d("STLOG (Next)", time.getTime().toString())
|
||||
alarmMgr.setRepeating(AlarmManager.RTC, time.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender) // Repeat every day
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class App : Application() {
|
||||
|
||||
companion object {
|
||||
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
}
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.app.PendingIntent
|
||||
import java.util.Calendar
|
||||
import android.app.AlarmManager
|
||||
import android.util.Log
|
||||
import android.app.Notification
|
||||
import android.app.NotificationManager
|
||||
|
||||
/**
|
||||
* Created by kprkpr on 18/07/17.
|
||||
* Here, functions for using in every part of app
|
||||
*/
|
||||
|
||||
|
||||
/** Restart activity without doing animations for refresh favs
|
||||
* @param act: Use "this.intent"
|
||||
* */
|
||||
fun restartActivity(act: AppCompatActivity){
|
||||
val intent = act.intent
|
||||
act.overridePendingTransition(0, 0)
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
|
||||
act.finish()
|
||||
act.overridePendingTransition(0, 0)
|
||||
act.startActivity(intent)
|
||||
}
|
||||
|
||||
|
||||
/* Call for putting alarm */
|
||||
fun putAlarm(context: Context) {
|
||||
var P = Prefs(context)
|
||||
//val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
/* Common vars for alarm config */
|
||||
val alarmMgr = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
val sender = PendingIntent.getBroadcast(context, 1, Intent(context, AlarmNotif::class.java), 0)
|
||||
|
||||
/* Cancel alarm first */
|
||||
alarmMgr.cancel(sender)
|
||||
//nm.cancel(1);
|
||||
|
||||
|
||||
var time = Calendar.getInstance()
|
||||
if (P.getNotifOn()) {
|
||||
if (P.getPersNotifOn()) { /* Persistent */
|
||||
var intent = Intent()
|
||||
intent.setAction("com.jkanetwork.st.frasesdeanime.notif")
|
||||
context.sendBroadcast(intent)
|
||||
|
||||
}else{ /* At x hour every day */
|
||||
|
||||
/* 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. */
|
||||
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 */
|
||||
time.add(Calendar.DATE, 1)
|
||||
}
|
||||
|
||||
time.set(Calendar.HOUR_OF_DAY, P.getHour())
|
||||
time.set(Calendar.MINUTE, P.getMinute())
|
||||
time.set(Calendar.SECOND, 0)
|
||||
Log.d("STLOG (Next)", time.getTime().toString())
|
||||
alarmMgr.setRepeating(AlarmManager.RTC, time.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender) // Repeat every day
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class App : Application() {
|
||||
|
||||
companion object {
|
||||
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
}
|
||||
}
|
||||
@@ -1,94 +1,94 @@
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
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.MenuItem
|
||||
import android.widget.AdapterView
|
||||
import android.content.ClipboardManager
|
||||
import android.content.ClipData
|
||||
import org.jetbrains.anko.*
|
||||
|
||||
//import kotlinx.android.synthetic.main.activity_simplelistview.*
|
||||
|
||||
/**
|
||||
* Created by kprkpr on 25/07/17.
|
||||
* Help: https://www.youtube.com/watch?v=x-M1L6tcsLo
|
||||
*/
|
||||
class FavsActivity : AppCompatActivity(){
|
||||
|
||||
/* For DSL bind */
|
||||
lateinit var view_list : ListView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
/** Layout in DSL */
|
||||
verticalLayout {
|
||||
view_list = listView {
|
||||
}.lparams(width = matchParent, height = matchParent) {
|
||||
}
|
||||
}
|
||||
|
||||
val data = ArrayList<HashMap<String,String>>()
|
||||
var db = SQLiteHelper(applicationContext)
|
||||
val listIDFrases = db.getAllIDFavs()
|
||||
val length = listIDFrases.size
|
||||
|
||||
for (i in 0..length -1){
|
||||
val item = HashMap<String, String>()
|
||||
item.put("sentence",db.getSentenceFromIDF(listIDFrases[i]))
|
||||
item.put("anime",db.getAnimeFromIDF(listIDFrases[i]))
|
||||
data.add(item)
|
||||
}
|
||||
|
||||
view_list.adapter = SimpleAdapter(this,data,android.R.layout.simple_list_item_2,
|
||||
arrayOf("sentence","anime"), intArrayOf(android.R.id.text1,android.R.id.text2))
|
||||
|
||||
registerForContextMenu(view_list)
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(menu: ContextMenu, v: View,
|
||||
menuInfo: ContextMenu.ContextMenuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo)
|
||||
val inflater = getMenuInflater()
|
||||
inflater.inflate(R.menu.menu_favsentence, menu)
|
||||
}
|
||||
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
val info = item.getMenuInfo() as AdapterView.AdapterContextMenuInfo
|
||||
val obj = view_list.getItemAtPosition(info.position) as HashMap<String, String>
|
||||
|
||||
when (item.getItemId()) {
|
||||
R.id.copy -> {
|
||||
var clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
clipboard.setPrimaryClip(ClipData.newPlainText("Sentence", "${obj.get("sentence")} (${obj.get("anime")}) \n ${this.getString(R.string.sharefrom)}"))
|
||||
toast("Copiado al portapapeles")
|
||||
return true
|
||||
}
|
||||
R.id.delfav -> {
|
||||
var db = SQLiteHelper(applicationContext)
|
||||
val IDFavs = db.getAllIDFavs()
|
||||
db.setFav(IDFavs[info.position])
|
||||
restartActivity(this)
|
||||
return true
|
||||
}
|
||||
R.id.share -> {
|
||||
share("${obj.get("sentence")} (${obj.get("anime")}) \n ${this.getString(R.string.sharefrom)}")
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
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.MenuItem
|
||||
import android.widget.AdapterView
|
||||
import android.content.ClipboardManager
|
||||
import android.content.ClipData
|
||||
import org.jetbrains.anko.*
|
||||
|
||||
//import kotlinx.android.synthetic.main.activity_simplelistview.*
|
||||
|
||||
/**
|
||||
* Created by kprkpr on 25/07/17.
|
||||
* Help: https://www.youtube.com/watch?v=x-M1L6tcsLo
|
||||
*/
|
||||
class FavsActivity : AppCompatActivity(){
|
||||
|
||||
/* For DSL bind */
|
||||
lateinit var view_list : ListView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
/** Layout in DSL */
|
||||
verticalLayout {
|
||||
view_list = listView {
|
||||
}.lparams(width = matchParent, height = matchParent) {
|
||||
}
|
||||
}
|
||||
|
||||
val data = ArrayList<HashMap<String,String>>()
|
||||
var db = SQLiteHelper(applicationContext)
|
||||
val listIDFrases = db.getAllIDFavs()
|
||||
val length = listIDFrases.size
|
||||
|
||||
for (i in 0..length -1){
|
||||
val item = HashMap<String, String>()
|
||||
item.put("sentence",db.getSentenceFromIDF(listIDFrases[i]))
|
||||
item.put("anime",db.getAnimeFromIDF(listIDFrases[i]))
|
||||
data.add(item)
|
||||
}
|
||||
|
||||
view_list.adapter = SimpleAdapter(this,data,android.R.layout.simple_list_item_2,
|
||||
arrayOf("sentence","anime"), intArrayOf(android.R.id.text1,android.R.id.text2))
|
||||
|
||||
registerForContextMenu(view_list)
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateContextMenu(menu: ContextMenu, v: View,
|
||||
menuInfo: ContextMenu.ContextMenuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo)
|
||||
val inflater = getMenuInflater()
|
||||
inflater.inflate(R.menu.menu_favsentence, menu)
|
||||
}
|
||||
|
||||
|
||||
override fun onContextItemSelected(item: MenuItem): Boolean {
|
||||
val info = item.getMenuInfo() as AdapterView.AdapterContextMenuInfo
|
||||
val obj = view_list.getItemAtPosition(info.position) as HashMap<String, String>
|
||||
|
||||
when (item.getItemId()) {
|
||||
R.id.copy -> {
|
||||
var clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
clipboard.setPrimaryClip(ClipData.newPlainText("Sentence", "${obj.get("sentence")} (${obj.get("anime")}) \n ${this.getString(R.string.sharefrom)}"))
|
||||
toast("Copiado al portapapeles")
|
||||
return true
|
||||
}
|
||||
R.id.delfav -> {
|
||||
var db = SQLiteHelper(applicationContext)
|
||||
val IDFavs = db.getAllIDFavs()
|
||||
db.setFav(IDFavs[info.position])
|
||||
restartActivity(this)
|
||||
return true
|
||||
}
|
||||
R.id.share -> {
|
||||
share("${obj.get("sentence")} (${obj.get("anime")}) \n ${this.getString(R.string.sharefrom)}")
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,293 +1,276 @@
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import org.jetbrains.anko.*
|
||||
import android.util.Log
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.MenuItem
|
||||
import java.util.Calendar
|
||||
import java.text.DateFormatSymbols
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import android.widget.Toast
|
||||
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
|
||||
/* Ads */
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.ads.mediation.admob.AdMobAdapter
|
||||
import com.google.android.gms.ads.MobileAds
|
||||
import com.google.android.gms.ads.reward.RewardItem
|
||||
import com.google.android.gms.ads.reward.RewardedVideoAd
|
||||
import com.google.android.gms.ads.reward.RewardedVideoAdListener
|
||||
|
||||
import com.google.android.gms.ads.AdView
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity(), RewardedVideoAdListener {
|
||||
|
||||
// Overrides for making it compile ok, it needs all methods
|
||||
override fun onRewardedVideoAdLeftApplication() {}
|
||||
override fun onRewardedVideoAdClosed() {}
|
||||
override fun onRewardedVideoAdFailedToLoad(errorCode: Int) {}
|
||||
override fun onRewardedVideoAdLoaded() {}
|
||||
override fun onRewardedVideoAdOpened() {}
|
||||
override fun onRewardedVideoStarted() {}
|
||||
override fun onRewardedVideoCompleted() {}
|
||||
|
||||
/* Prefs, database init and calendar data */
|
||||
lateinit var P: Prefs
|
||||
lateinit var db: SQLiteHelper
|
||||
var cal = Calendar.getInstance()
|
||||
var dayS = cal.get(Calendar.DAY_OF_MONTH)
|
||||
var monthS = cal.get(Calendar.MONTH)+1
|
||||
var yearS = cal.get(Calendar.YEAR)
|
||||
|
||||
var IDFraseS = -2 /* Error if not changes */
|
||||
|
||||
lateinit var mRewardedVideoAd: RewardedVideoAd
|
||||
lateinit var mAdView : AdView
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
P = Prefs(applicationContext)
|
||||
db = SQLiteHelper(applicationContext)
|
||||
|
||||
|
||||
/* Ads */
|
||||
// Initialize the Mobile Ads SDK.
|
||||
MobileAds.initialize(this, this.getString(R.string.admob_id))
|
||||
|
||||
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this)
|
||||
mRewardedVideoAd.setRewardedVideoAdListener(this);
|
||||
|
||||
val extras = Bundle()
|
||||
|
||||
extras.putString("max_ad_content_rating", "PG") //Non adult ads
|
||||
|
||||
mAdView = adView
|
||||
val adRequest = AdRequest.Builder().addNetworkExtrasBundle(AdMobAdapter::class.java, extras).build()
|
||||
mAdView.loadAd(adRequest)
|
||||
|
||||
/* Check if first time or not, for welcoming user */
|
||||
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" +
|
||||
"Selecciona de la siguiente lista los que más te gusten para empezar."){
|
||||
positiveButton("Empezemos") {startActivity<AnimesSelActivity>()}
|
||||
}.show()
|
||||
|
||||
}else {
|
||||
/* Check if no anime is selected */
|
||||
if (db.getCountAnimeSel() == 0) {
|
||||
alert("No tienes ningún anime seleccionado, ¿Quieres seleccionarlos ahora?", "No hay animes seleccionados") {
|
||||
positiveButton("Si") { startActivity<AnimesSelActivity>() }
|
||||
negativeButton("No") { }
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
|
||||
//For "Vote us in Play Store"
|
||||
if (P.getRateCountdown() == 0){
|
||||
alert("¿Te gusta la apliación? ¿Crees que la falta algo?"){
|
||||
positiveButton("Danos tu opinión") {browse("https://play.google.com/store/apps/details?id=com.jkanetwork.st.frasesdeanime")}
|
||||
negativeButton("Más tarde") { }
|
||||
}.show()
|
||||
P.setRateCountdown(); //To -1, if not..you know
|
||||
}else{
|
||||
P.setRateCountdown(); //Countdown one
|
||||
}
|
||||
|
||||
|
||||
/* Button listeners */
|
||||
btn_fav.setOnClickListener() {
|
||||
db.setFav(IDFraseS)
|
||||
if (db.getFav(IDFraseS) == true) {
|
||||
btn_fav.setBackgroundResource(R.drawable.star_on);
|
||||
}else{
|
||||
btn_fav.setBackgroundResource(R.drawable.star_off);
|
||||
}
|
||||
}
|
||||
|
||||
btn_share.setOnClickListener() {
|
||||
share("${txt_sentence.text} (${txt_anime.text}) \n ${this.getString(R.string.sharefrom)}")
|
||||
}
|
||||
|
||||
btn_change.setOnClickListener() {
|
||||
if (mRewardedVideoAd.isLoaded() && IDFraseS > 0) {
|
||||
mRewardedVideoAd.show();
|
||||
}else if (IDFraseS <= 0) {
|
||||
alert("Aquí no puedes ver una frase aún, no sirve de nada pulsar el botón") {
|
||||
positiveButton("Ok") { }
|
||||
}.show()
|
||||
}else{
|
||||
alert("Aún no hay un anuncio disponible, espere") {
|
||||
positiveButton("Ok") { }
|
||||
}.show()
|
||||
preloadAd()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Button for previous day
|
||||
btn_prev.setOnClickListener() {
|
||||
if (dayS == 1){
|
||||
if (monthS == 1){
|
||||
monthS=12
|
||||
yearS -= 1
|
||||
}else{
|
||||
monthS -=1
|
||||
}
|
||||
if (monthS in arrayOf(1, 3, 5,7,8,10,12)){
|
||||
dayS = 31
|
||||
}else if (monthS == 2){
|
||||
dayS = 28
|
||||
}else{
|
||||
dayS = 30
|
||||
}
|
||||
}else{
|
||||
dayS -=1
|
||||
}
|
||||
changeData()
|
||||
}
|
||||
|
||||
//Button of next (day) sentence
|
||||
btn_next.setOnClickListener() {
|
||||
if ((monthS in arrayOf(1, 3, 5,7,8,10) && dayS == 31) || (monthS == 2 && dayS == 28) || (monthS in arrayOf(2,4,6,9,11) && dayS == 30)){
|
||||
monthS += 1
|
||||
dayS = 1
|
||||
}else if (dayS == 31 && monthS == 12){ //New Year
|
||||
monthS = 1
|
||||
dayS = 1
|
||||
}else{
|
||||
dayS +=1
|
||||
}
|
||||
changeData()
|
||||
}
|
||||
|
||||
btn_today.setOnClickListener(){
|
||||
//Go back to today
|
||||
dayS = cal.get(Calendar.DAY_OF_MONTH)
|
||||
monthS = cal.get(Calendar.MONTH)+1
|
||||
yearS = cal.get(Calendar.YEAR)
|
||||
changeData()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** At onResume, called after onCreate and in resume, load ad things and refresh calendar data */
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
txt_sentence.setMovementMethod(ScrollingMovementMethod()) //Make sentence text scrollable
|
||||
|
||||
preloadAd() //Load (Again) ads
|
||||
|
||||
cal = Calendar.getInstance() //Refresh calendar
|
||||
//Refresh day
|
||||
dayS = cal.get(Calendar.DAY_OF_MONTH)
|
||||
monthS = cal.get(Calendar.MONTH)+1
|
||||
yearS = cal.get(Calendar.YEAR)
|
||||
changeData()
|
||||
}
|
||||
|
||||
/** "Close" app on back button */
|
||||
override fun onBackPressed() {
|
||||
moveTaskToBack(true)
|
||||
}
|
||||
|
||||
/** It returns the month name */
|
||||
fun getMonth(month: Int): String {
|
||||
val str = DateFormatSymbols().getMonths()[month - 1]
|
||||
return str.capitalize()
|
||||
}
|
||||
|
||||
/** This function replaces texts of main activity to sentence using IDFraseS var
|
||||
*/
|
||||
fun changeData(){
|
||||
IDFraseS = db.getIDFrase(yearS,monthS, dayS)
|
||||
txt_sentence.setText(db.getSentenceFromIDF(IDFraseS))
|
||||
txt_anime.setText(db.getAnimeFromIDF(IDFraseS))
|
||||
//txt_date.setText("Frase de hoy")
|
||||
txt_date.setText("Frase del $dayS de ${getMonth(monthS)}")
|
||||
/* Set fav icon */
|
||||
if (db.getFav(IDFraseS) == true) {
|
||||
btn_fav.setBackgroundResource(R.drawable.star_on);
|
||||
}else{
|
||||
btn_fav.setBackgroundResource(R.drawable.star_off);
|
||||
}
|
||||
}
|
||||
|
||||
/** This changes sentence of day you are seeing */
|
||||
override fun onRewarded(reward: RewardItem) {
|
||||
alert {
|
||||
customView {
|
||||
linearLayout {
|
||||
imageView {
|
||||
imageResource = R.drawable.gato
|
||||
}.lparams(width = matchParent) {
|
||||
margin = dip(4)
|
||||
}
|
||||
}
|
||||
}
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.main, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean{
|
||||
when (item.getItemId()) {
|
||||
R.id.favs -> {
|
||||
startActivity<FavsActivity>()
|
||||
return true
|
||||
}
|
||||
R.id.anime -> {
|
||||
startActivity<AnimesSelActivity>()
|
||||
return true
|
||||
}
|
||||
R.id.options -> {
|
||||
startActivity<OptsActivity>()
|
||||
return true
|
||||
}
|
||||
R.id.about -> {
|
||||
startActivity<AboutActivity>()
|
||||
return true
|
||||
}
|
||||
R.id.exit -> {
|
||||
moveTaskToBack(true) /* Returns to "desktop" */
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun preloadAd() {
|
||||
var Adr = AdRequest.Builder()
|
||||
Adr.addTestDevice("C0119E16F190120A0481C80734939D71")
|
||||
Adr.addTestDevice("4264F289943AD2719C3F0ECB2CD4556A")
|
||||
Adr.addTestDevice("D0CF3543C15E51623C67081FA8B64C2B")
|
||||
|
||||
val extras = Bundle()
|
||||
extras.putString("max_ad_content_rating", "PG") //Non adult ads
|
||||
|
||||
mRewardedVideoAd.loadAd(this.getString(R.string.admob_videoid), Adr.addNetworkExtrasBundle(AdMobAdapter::class.java, extras).build())
|
||||
}
|
||||
|
||||
}
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import org.jetbrains.anko.*
|
||||
import android.util.Log
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.view.Menu
|
||||
import android.view.View
|
||||
import android.view.MenuItem
|
||||
import java.util.Calendar
|
||||
import java.text.DateFormatSymbols
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import android.widget.Toast
|
||||
|
||||
/* Ads */
|
||||
import com.google.android.gms.ads.AdRequest
|
||||
import com.google.android.gms.ads.rewarded.RewardedAd;
|
||||
|
||||
|
||||
import android.text.method.ScrollingMovementMethod
|
||||
import com.google.android.gms.ads.LoadAdError
|
||||
import com.google.android.gms.ads.OnUserEarnedRewardListener
|
||||
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback
|
||||
import com.jkanetwork.st.frasesdeanime.databinding.ActivityMainBinding
|
||||
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
private var rewardedAd: RewardedAd? = null
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
|
||||
|
||||
/* Prefs, database init and calendar data */
|
||||
lateinit var P: Prefs
|
||||
lateinit var db: SQLiteHelper
|
||||
var cal = Calendar.getInstance()
|
||||
var dayS = cal.get(Calendar.DAY_OF_MONTH)
|
||||
var monthS = cal.get(Calendar.MONTH)+1
|
||||
var yearS = cal.get(Calendar.YEAR)
|
||||
|
||||
var IDFraseS = -2 /* Error if not changes */
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
P = Prefs(applicationContext)
|
||||
db = SQLiteHelper(applicationContext)
|
||||
|
||||
|
||||
/* Ads */
|
||||
// Initialize the Mobile Ads SDK.
|
||||
|
||||
var adRequest = AdRequest.Builder().build()
|
||||
RewardedAd.load(this,this.getString(R.string.admob_id), adRequest, object : RewardedAdLoadCallback() {
|
||||
override fun onAdFailedToLoad(adError: LoadAdError) {
|
||||
rewardedAd = null
|
||||
}
|
||||
|
||||
override fun onAdLoaded(ad: RewardedAd) {
|
||||
rewardedAd = ad
|
||||
}
|
||||
})
|
||||
|
||||
val extras = Bundle()
|
||||
|
||||
extras.putString("max_ad_content_rating", "PG") //Non adult ads
|
||||
|
||||
|
||||
/* Check if first time or not, for welcoming user */
|
||||
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" +
|
||||
"Selecciona de la siguiente lista los que más te gusten para empezar."){
|
||||
positiveButton("Empezemos") {startActivity<AnimesSelActivity>()}
|
||||
}.show()
|
||||
|
||||
}else {
|
||||
/* Check if no anime is selected */
|
||||
if (db.getCountAnimeSel() == 0) {
|
||||
alert("No tienes ningún anime seleccionado, ¿Quieres seleccionarlos ahora?", "No hay animes seleccionados") {
|
||||
positiveButton("Si") { startActivity<AnimesSelActivity>() }
|
||||
negativeButton("No") { }
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
|
||||
//For "Vote us in Play Store"
|
||||
if (P.getRateCountdown() == 0){
|
||||
alert("¿Te gusta la apliación? ¿Crees que la falta algo?"){
|
||||
positiveButton("Danos tu opinión") {browse("https://play.google.com/store/apps/details?id=com.jkanetwork.st.frasesdeanime")}
|
||||
negativeButton("Más tarde") { }
|
||||
}.show()
|
||||
P.setRateCountdown(); //To -1, if not..you know
|
||||
}else{
|
||||
P.setRateCountdown(); //Countdown one
|
||||
}
|
||||
|
||||
|
||||
/* Button listeners */
|
||||
binding.btnFav.setOnClickListener() {
|
||||
db.setFav(IDFraseS)
|
||||
if (db.getFav(IDFraseS)) {
|
||||
binding.btnFav.setBackgroundResource(R.drawable.star_on);
|
||||
}else{
|
||||
binding.btnFav.setBackgroundResource(R.drawable.star_off);
|
||||
}
|
||||
}
|
||||
|
||||
binding.btnShare.setOnClickListener() {
|
||||
share("${binding.txtSentence.text} (${binding.txtAnime.text}) \n ${this.getString(R.string.sharefrom)}")
|
||||
}
|
||||
|
||||
binding.btnChange.setOnClickListener() {
|
||||
|
||||
if (IDFraseS > 0) {
|
||||
rewardedAd?.let { ad ->
|
||||
ad.show(this, OnUserEarnedRewardListener { rewardItem ->
|
||||
// Handle the reward. ANUNCIO VISTO CORRECTAMENTE.
|
||||
alert {
|
||||
customView {
|
||||
linearLayout {
|
||||
imageView {
|
||||
imageResource = R.drawable.gato
|
||||
}.lparams(width = matchParent) {
|
||||
margin = dip(4)
|
||||
}
|
||||
}
|
||||
}
|
||||
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 {
|
||||
alert("Aún no hay un anuncio disponible, espere") {
|
||||
positiveButton("Ok") { }
|
||||
}.show()
|
||||
}
|
||||
}else{ // if (IDFraseS <= 0) {
|
||||
alert("Aquí no puedes ver una frase aún, no sirve de nada pulsar el botón") {
|
||||
positiveButton("Ok") { }
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Button for previous day
|
||||
binding.btnPrev.setOnClickListener() {
|
||||
if (dayS == 1){
|
||||
if (monthS == 1){
|
||||
monthS=12
|
||||
yearS -= 1
|
||||
}else{
|
||||
monthS -=1
|
||||
}
|
||||
if (monthS in arrayOf(1, 3, 5,7,8,10,12)){
|
||||
dayS = 31
|
||||
}else if (monthS == 2){
|
||||
dayS = 28
|
||||
}else{
|
||||
dayS = 30
|
||||
}
|
||||
}else{
|
||||
dayS -=1
|
||||
}
|
||||
changeData()
|
||||
}
|
||||
|
||||
//Button of next (day) sentence
|
||||
binding.btnNext.setOnClickListener() {
|
||||
if ((monthS in arrayOf(1, 3, 5,7,8,10) && dayS == 31) || (monthS == 2 && dayS == 28) || (monthS in arrayOf(2,4,6,9,11) && dayS == 30)){
|
||||
monthS += 1
|
||||
dayS = 1
|
||||
}else if (dayS == 31 && monthS == 12){ //New Year
|
||||
monthS = 1
|
||||
dayS = 1
|
||||
}else{
|
||||
dayS +=1
|
||||
}
|
||||
changeData()
|
||||
}
|
||||
|
||||
binding.btnToday.setOnClickListener(){
|
||||
//Go back to today
|
||||
dayS = cal.get(Calendar.DAY_OF_MONTH)
|
||||
monthS = cal.get(Calendar.MONTH)+1
|
||||
yearS = cal.get(Calendar.YEAR)
|
||||
changeData()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** At onResume, called after onCreate and in resume, load ad things and refresh calendar data */
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
binding.txtSentence.setMovementMethod(ScrollingMovementMethod()) //Make sentence text scrollable
|
||||
|
||||
cal = Calendar.getInstance() //Refresh calendar
|
||||
//Refresh day
|
||||
dayS = cal.get(Calendar.DAY_OF_MONTH)
|
||||
monthS = cal.get(Calendar.MONTH)+1
|
||||
yearS = cal.get(Calendar.YEAR)
|
||||
changeData()
|
||||
}
|
||||
|
||||
/** "Close" app on back button */
|
||||
override fun onBackPressed() {
|
||||
moveTaskToBack(true)
|
||||
}
|
||||
|
||||
/** It returns the month name */
|
||||
fun getMonth(month: Int): String {
|
||||
val str = DateFormatSymbols().getMonths()[month - 1]
|
||||
return str.capitalize()
|
||||
}
|
||||
|
||||
/** This function replaces texts of main activity to sentence using IDFraseS var
|
||||
*/
|
||||
fun changeData(){
|
||||
IDFraseS = db.getIDFrase(yearS,monthS, dayS)
|
||||
binding.txtSentence.setText(db.getSentenceFromIDF(IDFraseS))
|
||||
binding.txtAnime.setText(db.getAnimeFromIDF(IDFraseS))
|
||||
//txt_date.setText("Frase de hoy")
|
||||
binding.txtDate.setText("Frase del $dayS de ${getMonth(monthS)}")
|
||||
/* Set fav icon */
|
||||
if (db.getFav(IDFraseS)) {
|
||||
binding.btnFav.setBackgroundResource(R.drawable.star_on);
|
||||
}else{
|
||||
binding.btnFav.setBackgroundResource(R.drawable.star_off);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.main, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean{
|
||||
when (item.getItemId()) {
|
||||
R.id.favs -> {
|
||||
startActivity<FavsActivity>()
|
||||
return true
|
||||
}
|
||||
R.id.anime -> {
|
||||
startActivity<AnimesSelActivity>()
|
||||
return true
|
||||
}
|
||||
R.id.options -> {
|
||||
startActivity<OptsActivity>()
|
||||
return true
|
||||
}
|
||||
R.id.about -> {
|
||||
startActivity<AboutActivity>()
|
||||
return true
|
||||
}
|
||||
R.id.exit -> {
|
||||
moveTaskToBack(true) /* Returns to "desktop" */
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,99 +1,100 @@
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.content.Context
|
||||
import android.widget.ArrayAdapter
|
||||
import org.jetbrains.anko.*
|
||||
import kotlinx.android.synthetic.main.activity_opts.*
|
||||
import android.content.Intent
|
||||
import java.util.*
|
||||
import android.content.BroadcastReceiver
|
||||
|
||||
/**
|
||||
* Created by kprkpr on 30/08/17.
|
||||
*/
|
||||
class OptsActivity : AppCompatActivity(){
|
||||
|
||||
lateinit var P: Prefs
|
||||
|
||||
val cont = this
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_opts)
|
||||
|
||||
P = Prefs(applicationContext)
|
||||
|
||||
val hours = ArrayList<Int>()
|
||||
val minutes = ArrayList<Int>()
|
||||
|
||||
for (i in 0..23){
|
||||
hours.add(i)
|
||||
}
|
||||
for (i in 0..59){
|
||||
minutes.add(i)
|
||||
}
|
||||
|
||||
var hoursAdapter = ArrayAdapter(this,android.R.layout.simple_list_item_1,hours)
|
||||
var minutesAdapter = ArrayAdapter(this,android.R.layout.simple_list_item_1,minutes)
|
||||
|
||||
hoursAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
minutesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
|
||||
spinnerHour.adapter = hoursAdapter
|
||||
spinnerMinute.adapter = minutesAdapter
|
||||
|
||||
spinnerHour.setSelection(P.getHour())
|
||||
spinnerMinute.setSelection(P.getMinute())
|
||||
|
||||
chk_alarm.setChecked(P.getNotifOn())
|
||||
chk_persistent.setChecked(P.getPersNotifOn())
|
||||
|
||||
setEnabledParts()
|
||||
|
||||
/* Button listeners */
|
||||
chk_alarm.setOnClickListener() {
|
||||
setEnabledParts()
|
||||
}
|
||||
chk_persistent.setOnClickListener() {
|
||||
setEnabledParts()
|
||||
}
|
||||
|
||||
btn_SaveNotif.setOnClickListener() {
|
||||
|
||||
P.setHour(spinnerHour.getSelectedItem().toString().toInt())
|
||||
P.setMinute(spinnerMinute.getSelectedItem().toString().toInt())
|
||||
|
||||
P.setNotifOn(chk_alarm.isChecked())
|
||||
P.setPersNotifOn(chk_persistent.isChecked())
|
||||
|
||||
val nm = applicationContext.notificationManager
|
||||
nm.cancel(1); //Canel notif before service going on, for persistent notification problems
|
||||
putAlarm(this)
|
||||
if (chk_persistent.isChecked() && chk_alarm.isChecked()) {
|
||||
this.startService(Intent(this, AlarmNotif::class.java))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun setEnabledParts() {
|
||||
if (chk_alarm.isChecked()) {
|
||||
chk_persistent.setEnabled(true)
|
||||
/* This other checks is chk_persistent checked dependent */
|
||||
if (chk_persistent.isChecked()) {
|
||||
spinnerHour.setEnabled(false)
|
||||
spinnerMinute.setEnabled(false)
|
||||
} else {
|
||||
spinnerHour.setEnabled(true)
|
||||
spinnerMinute.setEnabled(true)
|
||||
}
|
||||
} else {
|
||||
chk_persistent.setEnabled(false)
|
||||
spinnerHour.setEnabled(false)
|
||||
spinnerMinute.setEnabled(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.widget.ArrayAdapter
|
||||
import org.jetbrains.anko.*
|
||||
import android.content.Intent
|
||||
import java.util.*
|
||||
import android.content.BroadcastReceiver
|
||||
import com.jkanetwork.st.frasesdeanime.databinding.ActivityOptsBinding
|
||||
|
||||
/**
|
||||
* Created by kprkpr on 30/08/17.
|
||||
*/
|
||||
class OptsActivity : AppCompatActivity(){
|
||||
|
||||
private lateinit var binding: ActivityOptsBinding
|
||||
lateinit var P: Prefs
|
||||
|
||||
val cont = this
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityOptsBinding.inflate(layoutInflater)
|
||||
setContentView(R.layout.activity_opts)
|
||||
|
||||
P = Prefs(applicationContext)
|
||||
|
||||
val hours = ArrayList<Int>()
|
||||
val minutes = ArrayList<Int>()
|
||||
|
||||
for (i in 0..23){
|
||||
hours.add(i)
|
||||
}
|
||||
for (i in 0..59){
|
||||
minutes.add(i)
|
||||
}
|
||||
|
||||
var hoursAdapter = ArrayAdapter(this,android.R.layout.simple_list_item_1,hours)
|
||||
var minutesAdapter = ArrayAdapter(this,android.R.layout.simple_list_item_1,minutes)
|
||||
|
||||
hoursAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
minutesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
|
||||
binding.spinnerHour.adapter = hoursAdapter
|
||||
binding.spinnerMinute.adapter = minutesAdapter
|
||||
|
||||
binding.spinnerHour.setSelection(P.getHour())
|
||||
binding.spinnerMinute.setSelection(P.getMinute())
|
||||
|
||||
binding.chkAlarm.setChecked(P.getNotifOn())
|
||||
binding.chkPersistent.setChecked(P.getPersNotifOn())
|
||||
|
||||
setEnabledParts()
|
||||
|
||||
/* Button listeners */
|
||||
binding.chkAlarm.setOnClickListener() {
|
||||
setEnabledParts()
|
||||
}
|
||||
binding.chkPersistent.setOnClickListener() {
|
||||
setEnabledParts()
|
||||
}
|
||||
|
||||
binding.btnSaveNotif.setOnClickListener() {
|
||||
|
||||
P.setHour(binding.spinnerHour.getSelectedItem().toString().toInt())
|
||||
P.setMinute(binding.spinnerMinute.getSelectedItem().toString().toInt())
|
||||
|
||||
P.setNotifOn(binding.chkAlarm.isChecked())
|
||||
P.setPersNotifOn(binding.chkPersistent.isChecked())
|
||||
|
||||
val nm = applicationContext.notificationManager
|
||||
nm.cancel(1); //Canel notif before service going on, for persistent notification problems
|
||||
putAlarm(this)
|
||||
if (binding.chkPersistent.isChecked() && binding.chkAlarm.isChecked()) {
|
||||
this.startService(Intent(this, AlarmNotif::class.java))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun setEnabledParts() {
|
||||
if (binding.chkAlarm.isChecked()) {
|
||||
binding.chkPersistent.setEnabled(true)
|
||||
/* This other checks is chk_persistent checked dependent */
|
||||
if (binding.chkPersistent.isChecked()) {
|
||||
binding.spinnerHour.setEnabled(false)
|
||||
binding.spinnerMinute.setEnabled(false)
|
||||
} else {
|
||||
binding.spinnerHour.setEnabled(true)
|
||||
binding.spinnerMinute.setEnabled(true)
|
||||
}
|
||||
} else {
|
||||
binding.chkPersistent.setEnabled(false)
|
||||
binding.spinnerHour.setEnabled(false)
|
||||
binding.spinnerMinute.setEnabled(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,272 +1,272 @@
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import org.jetbrains.anko.db.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.Calendar
|
||||
import android.util.Log
|
||||
|
||||
/**
|
||||
* Created by kprkpr on 18/07/17.
|
||||
*/
|
||||
|
||||
/** ctx, DB.NAME, null, DB.Version */
|
||||
class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite", null, 8) {
|
||||
val context = ctx
|
||||
val db = this.getWritableDatabase()
|
||||
|
||||
// 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)
|
||||
companion object {
|
||||
private var instance: SQLiteHelper? = null
|
||||
|
||||
@Synchronized
|
||||
fun getInstance(ctx: Context): SQLiteHelper {
|
||||
if (instance == null) {
|
||||
instance = SQLiteHelper(ctx.applicationContext)
|
||||
}
|
||||
return instance!!
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
// Here you create tables
|
||||
db.execSQL("CREATE TABLE FRASESVI (" +
|
||||
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"TDay TEXT NOT NULL UNIQUE," +
|
||||
"IDFrase INTEGER)")
|
||||
db.createTable("FRASESFAV", true,
|
||||
"IDFrase" to INTEGER + UNIQUE)
|
||||
db.createTable("ANIMESON", true,
|
||||
"IDAnime" to INTEGER + UNIQUE)
|
||||
|
||||
//Load animes and sentences
|
||||
var queries: List<String> = readSqldata(R.raw.loadsqlfile).split(";\n");
|
||||
for (query in queries){
|
||||
if (!query.isBlank())
|
||||
db.execSQL(query);
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
// Here you can upgrade tables, as usual
|
||||
var queries: List<String> = readSqldata(R.raw.loadsqlfile).split(";\n");
|
||||
for (query in queries){
|
||||
if (!query.isBlank())
|
||||
db.execSQL(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun readSqldata(res: Int): String {
|
||||
//getting the file
|
||||
val inputStream: InputStream
|
||||
inputStream = context.getResources().openRawResource(res)
|
||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||
try {
|
||||
var i = inputStream.read()
|
||||
while (i != -1) {
|
||||
byteArrayOutputStream.write(i)
|
||||
i = inputStream.read()
|
||||
}
|
||||
inputStream.close()
|
||||
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return byteArrayOutputStream.toString()
|
||||
}
|
||||
|
||||
|
||||
/** Returns a boolean saying if a sentence is faved or not */
|
||||
fun getFav (IDFrase: Int): Boolean {
|
||||
val query = db.rawQuery("SELECT IDFrase FROM FRASESFAV WHERE IDFrase = '$IDFrase'", null)
|
||||
val res = query.getCount()
|
||||
query.close()
|
||||
if (res > 0){
|
||||
return true
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Changes the state of fav of a sentence
|
||||
* @param IDFrase: Sentence
|
||||
*/
|
||||
fun setFav (IDFrase: Int) {
|
||||
if (getFav(IDFrase) == false){
|
||||
db.insert("FRASESFAV","IDFrase" to IDFrase)
|
||||
}else{
|
||||
db.execSQL("DELETE FROM FRASESFAV WHERE IDFrase='$IDFrase'")
|
||||
}
|
||||
}
|
||||
|
||||
fun getSentenceFromIDF (IDFrase: Int): String {
|
||||
if (IDFrase == 0){ return "No hay más frases disponibles..."}
|
||||
if (IDFrase == -1){ return "No puedes ver aún esta frase"}
|
||||
if (IDFrase == -2){ return "Error inesperado"}
|
||||
val c = db.rawQuery("SELECT Frase FROM FRASES WHERE IDFrase = '$IDFrase'", null)
|
||||
c.moveToFirst()
|
||||
val ret = c.getString(0)
|
||||
c.close()
|
||||
return ret
|
||||
}
|
||||
|
||||
fun getAnimeFromIDF (IDFrase: Int): String {
|
||||
if (IDFrase <= 0){ return "..."}
|
||||
val c = db.rawQuery("SELECT Name FROM ANIMES WHERE IDAnime = (SELECT IDAnime FROM FRASES WHERE IDFrase = '$IDFrase')", null)
|
||||
c.moveToFirst()
|
||||
val ret = c.getString(0)
|
||||
c.close()
|
||||
return ret
|
||||
}
|
||||
|
||||
fun getIDAnimeFromName (Name: String): Int {
|
||||
var query = db.select("ANIMES", "IDAnime").whereArgs("Name = '$Name'")
|
||||
return query.parseSingle(IntParser)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun getIDFrase (year: Int,month: Int, day: Int): Int {
|
||||
val cal = Calendar.getInstance()
|
||||
/* First Integer to Strings of format YYYYMMDD for store and compare */
|
||||
val diaArg = "${year}${month.format(2)}${day.format(2)}"
|
||||
val diaAct = "${cal.get(Calendar.YEAR)}${(cal.get(Calendar.MONTH)+1).format(2)}${cal.get(Calendar.DAY_OF_MONTH).format(2)}"
|
||||
|
||||
/* Query db looking for the sentence. If there are not loaded yet, see (else if) if they can show a new one, if criteria is true. If not, not show sentence */
|
||||
var query = db.rawQuery("SELECT IDFrase FROM FRASESVI WHERE TDay = '$diaArg'", null)
|
||||
if (query.getCount() > 0){
|
||||
query.moveToFirst()
|
||||
val ret = query.getInt(0)
|
||||
query.close()
|
||||
return ret
|
||||
}else if (diaArg == diaAct || diaArg.toInt() < diaAct.toInt() && db.rawQuery("SELECT IDFrase FROM FRASESVI WHERE Tday < '$diaArg'", null).count > 0 ) {
|
||||
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.moveToFirst()
|
||||
db.insert("FRASESVI",
|
||||
"TDay" to diaArg,
|
||||
"IDFrase" to query.getString(0))
|
||||
val ret = query.getInt(0)
|
||||
query.close()
|
||||
return ret
|
||||
}
|
||||
catch (e: Exception) {
|
||||
return 0 //No more sentences
|
||||
}
|
||||
}else{
|
||||
return -1 //Day not yet
|
||||
}
|
||||
}
|
||||
|
||||
fun getIDFraseHoy(): Int {
|
||||
val cal = Calendar.getInstance()
|
||||
//Month + 1 because Android starts with month=0
|
||||
return getIDFrase(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH))
|
||||
}
|
||||
|
||||
fun getAllIDFavs(): Array<Int>{
|
||||
var query = db.select("FRASESFAV", "IDFrase")
|
||||
var list = query.parseList(IntParser)
|
||||
return list.toTypedArray()
|
||||
}
|
||||
|
||||
fun getAllAnimeIDs(): Array<Int>{
|
||||
var query = db.select("ANIMES", "IDAnime").orderBy("Name", SqlOrderDirection.ASC)
|
||||
var list = query.parseList(IntParser)
|
||||
return list.toTypedArray()
|
||||
}
|
||||
|
||||
fun getAllAnimeNames(): Array<String>{
|
||||
var query = db.select("ANIMES", "Name").orderBy("Name", SqlOrderDirection.ASC)
|
||||
var list = query.parseList(StringParser)
|
||||
return list.toTypedArray()
|
||||
}
|
||||
|
||||
/** Return if the anime asked by [IDA] is selected */
|
||||
fun getAnimeSel(IDA: Int): Boolean{
|
||||
val query = db.rawQuery("SELECT IDAnime FROM ANIMESON WHERE IDAnime = '$IDA'", null)
|
||||
val res = query.getCount()
|
||||
query.close()
|
||||
if (res > 0){
|
||||
return true
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Changes the state of a selected or not anime
|
||||
* @param IDAnime: Anime
|
||||
*/
|
||||
fun setAnimeSel (IDAnime: Int) {
|
||||
if (getAnimeSel(IDAnime) == false){
|
||||
db.insert("ANIMESON","IDAnime" to IDAnime)
|
||||
}else{
|
||||
db.execSQL("DELETE FROM ANIMESON WHERE IDAnime='$IDAnime'")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Return how much animes are selected (For knowing if 0) */
|
||||
fun getCountAnimeSel(): Int{
|
||||
val query = db.rawQuery("SELECT COUNT(*) FROM ANIMESON", null)
|
||||
query.moveToFirst()
|
||||
val ret = query.getInt(0)
|
||||
query.close();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Deletes the sentence of the day passed as argument yearS,monthS, dayS
|
||||
* @param year: Year selected
|
||||
* @param month: Month selected
|
||||
* @param day: Day selected
|
||||
*/
|
||||
fun delSentence (year: Int, month: Int, day: Int) {
|
||||
val diaArg = "${year}${month.format(2)}${day.format(2)}"
|
||||
db.execSQL("DELETE FROM FRASESVI WHERE TDay='$diaArg'")
|
||||
}
|
||||
|
||||
|
||||
/** This funcion selects or desselects all animes from selected to show */
|
||||
fun setAllAnimeSel(){
|
||||
var 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)
|
||||
db.execSQL("DELETE FROM ANIMESON")
|
||||
if (selectAll == false){ //Set all
|
||||
var animeIDs = getAllAnimeIDs()
|
||||
|
||||
for (pos in animeIDs){
|
||||
db.insert("ANIMESON",
|
||||
"IDAnime" to animeIDs[pos-1]) //Pos is a count, arrays start at 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** It returns if all animes are selected or not */
|
||||
fun getAllAnimeSel(): Boolean{
|
||||
var set = getCountAnimeSel();
|
||||
var countanime = getAllAnimeIDs().size;
|
||||
if (set == countanime){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** It returns to program that this sentence can't be seen */
|
||||
fun getSentenceCanBeSeen(year: Int,month: Int, day: Int): Boolean {
|
||||
//TODO, return 0 when if check this sentence will be "nothing", for disable button
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Access property for Context
|
||||
val Context.database: SQLiteHelper
|
||||
package com.jkanetwork.st.frasesdeanime
|
||||
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import org.jetbrains.anko.db.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.Calendar
|
||||
import android.util.Log
|
||||
|
||||
/**
|
||||
* Created by kprkpr on 18/07/17.
|
||||
*/
|
||||
|
||||
/** ctx, DB.NAME, null, DB.Version */
|
||||
class SQLiteHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, "otaku.sqlite", null, 8) {
|
||||
val context = ctx
|
||||
val db = this.getWritableDatabase()
|
||||
|
||||
// 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)
|
||||
companion object {
|
||||
private var instance: SQLiteHelper? = null
|
||||
|
||||
@Synchronized
|
||||
fun getInstance(ctx: Context): SQLiteHelper {
|
||||
if (instance == null) {
|
||||
instance = SQLiteHelper(ctx.applicationContext)
|
||||
}
|
||||
return instance!!
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
// Here you create tables
|
||||
db.execSQL("CREATE TABLE FRASESVI (" +
|
||||
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
|
||||
"TDay TEXT NOT NULL UNIQUE," +
|
||||
"IDFrase INTEGER)")
|
||||
db.createTable("FRASESFAV", true,
|
||||
"IDFrase" to INTEGER + UNIQUE)
|
||||
db.createTable("ANIMESON", true,
|
||||
"IDAnime" to INTEGER + UNIQUE)
|
||||
|
||||
//Load animes and sentences
|
||||
var queries: List<String> = readSqldata(R.raw.loadsqlfile).split(";\n");
|
||||
for (query in queries){
|
||||
if (!query.isBlank())
|
||||
db.execSQL(query);
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
// Here you can upgrade tables, as usual
|
||||
var queries: List<String> = readSqldata(R.raw.loadsqlfile).split(";\n");
|
||||
for (query in queries){
|
||||
if (!query.isBlank())
|
||||
db.execSQL(query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun readSqldata(res: Int): String {
|
||||
//getting the file
|
||||
val inputStream: InputStream
|
||||
inputStream = context.getResources().openRawResource(res)
|
||||
val byteArrayOutputStream = ByteArrayOutputStream()
|
||||
try {
|
||||
var i = inputStream.read()
|
||||
while (i != -1) {
|
||||
byteArrayOutputStream.write(i)
|
||||
i = inputStream.read()
|
||||
}
|
||||
inputStream.close()
|
||||
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return byteArrayOutputStream.toString()
|
||||
}
|
||||
|
||||
|
||||
/** Returns a boolean saying if a sentence is faved or not */
|
||||
fun getFav (IDFrase: Int): Boolean {
|
||||
val query = db.rawQuery("SELECT IDFrase FROM FRASESFAV WHERE IDFrase = '$IDFrase'", null)
|
||||
val res = query.getCount()
|
||||
query.close()
|
||||
if (res > 0){
|
||||
return true
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Changes the state of fav of a sentence
|
||||
* @param IDFrase: Sentence
|
||||
*/
|
||||
fun setFav (IDFrase: Int) {
|
||||
if (getFav(IDFrase) == false){
|
||||
db.insert("FRASESFAV","IDFrase" to IDFrase)
|
||||
}else{
|
||||
db.execSQL("DELETE FROM FRASESFAV WHERE IDFrase='$IDFrase'")
|
||||
}
|
||||
}
|
||||
|
||||
fun getSentenceFromIDF (IDFrase: Int): String {
|
||||
if (IDFrase == 0){ return "No hay más frases disponibles..."}
|
||||
if (IDFrase == -1){ return "No puedes ver aún esta frase"}
|
||||
if (IDFrase == -2){ return "Error inesperado"}
|
||||
val c = db.rawQuery("SELECT Frase FROM FRASES WHERE IDFrase = '$IDFrase'", null)
|
||||
c.moveToFirst()
|
||||
val ret = c.getString(0)
|
||||
c.close()
|
||||
return ret
|
||||
}
|
||||
|
||||
fun getAnimeFromIDF (IDFrase: Int): String {
|
||||
if (IDFrase <= 0){ return "..."}
|
||||
val c = db.rawQuery("SELECT Name FROM ANIMES WHERE IDAnime = (SELECT IDAnime FROM FRASES WHERE IDFrase = '$IDFrase')", null)
|
||||
c.moveToFirst()
|
||||
val ret = c.getString(0)
|
||||
c.close()
|
||||
return ret
|
||||
}
|
||||
|
||||
fun getIDAnimeFromName (Name: String): Int {
|
||||
var query = db.select("ANIMES", "IDAnime").whereArgs("Name = '$Name'")
|
||||
return query.parseSingle(IntParser)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun getIDFrase (year: Int,month: Int, day: Int): Int {
|
||||
val cal = Calendar.getInstance()
|
||||
/* First Integer to Strings of format YYYYMMDD for store and compare */
|
||||
val diaArg = "${year}${month.format(2)}${day.format(2)}"
|
||||
val diaAct = "${cal.get(Calendar.YEAR)}${(cal.get(Calendar.MONTH)+1).format(2)}${cal.get(Calendar.DAY_OF_MONTH).format(2)}"
|
||||
|
||||
/* Query db looking for the sentence. If there are not loaded yet, see (else if) if they can show a new one, if criteria is true. If not, not show sentence */
|
||||
var query = db.rawQuery("SELECT IDFrase FROM FRASESVI WHERE TDay = '$diaArg'", null)
|
||||
if (query.getCount() > 0){
|
||||
query.moveToFirst()
|
||||
val ret = query.getInt(0)
|
||||
query.close()
|
||||
return ret
|
||||
}else if (diaArg == diaAct || diaArg.toInt() < diaAct.toInt() && db.rawQuery("SELECT IDFrase FROM FRASESVI WHERE Tday < '$diaArg'", null).count > 0 ) {
|
||||
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.moveToFirst()
|
||||
db.insert("FRASESVI",
|
||||
"TDay" to diaArg,
|
||||
"IDFrase" to query.getString(0))
|
||||
val ret = query.getInt(0)
|
||||
query.close()
|
||||
return ret
|
||||
}
|
||||
catch (e: Exception) {
|
||||
return 0 //No more sentences
|
||||
}
|
||||
}else{
|
||||
return -1 //Day not yet
|
||||
}
|
||||
}
|
||||
|
||||
fun getIDFraseHoy(): Int {
|
||||
val cal = Calendar.getInstance()
|
||||
//Month + 1 because Android starts with month=0
|
||||
return getIDFrase(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH) + 1, cal.get(Calendar.DAY_OF_MONTH))
|
||||
}
|
||||
|
||||
fun getAllIDFavs(): Array<Int>{
|
||||
var query = db.select("FRASESFAV", "IDFrase")
|
||||
var list = query.parseList(IntParser)
|
||||
return list.toTypedArray()
|
||||
}
|
||||
|
||||
fun getAllAnimeIDs(): Array<Int>{
|
||||
var query = db.select("ANIMES", "IDAnime").orderBy("Name", SqlOrderDirection.ASC)
|
||||
var list = query.parseList(IntParser)
|
||||
return list.toTypedArray()
|
||||
}
|
||||
|
||||
fun getAllAnimeNames(): Array<String>{
|
||||
var query = db.select("ANIMES", "Name").orderBy("Name", SqlOrderDirection.ASC)
|
||||
var list = query.parseList(StringParser)
|
||||
return list.toTypedArray()
|
||||
}
|
||||
|
||||
/** Return if the anime asked by [IDA] is selected */
|
||||
fun getAnimeSel(IDA: Int): Boolean{
|
||||
val query = db.rawQuery("SELECT IDAnime FROM ANIMESON WHERE IDAnime = '$IDA'", null)
|
||||
val res = query.getCount()
|
||||
query.close()
|
||||
if (res > 0){
|
||||
return true
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** Changes the state of a selected or not anime
|
||||
* @param IDAnime: Anime
|
||||
*/
|
||||
fun setAnimeSel (IDAnime: Int) {
|
||||
if (getAnimeSel(IDAnime) == false){
|
||||
db.insert("ANIMESON","IDAnime" to IDAnime)
|
||||
}else{
|
||||
db.execSQL("DELETE FROM ANIMESON WHERE IDAnime='$IDAnime'")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Return how much animes are selected (For knowing if 0) */
|
||||
fun getCountAnimeSel(): Int{
|
||||
val query = db.rawQuery("SELECT COUNT(*) FROM ANIMESON", null)
|
||||
query.moveToFirst()
|
||||
val ret = query.getInt(0)
|
||||
query.close();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** Deletes the sentence of the day passed as argument yearS,monthS, dayS
|
||||
* @param year: Year selected
|
||||
* @param month: Month selected
|
||||
* @param day: Day selected
|
||||
*/
|
||||
fun delSentence (year: Int, month: Int, day: Int) {
|
||||
val diaArg = "${year}${month.format(2)}${day.format(2)}"
|
||||
db.execSQL("DELETE FROM FRASESVI WHERE TDay='$diaArg'")
|
||||
}
|
||||
|
||||
|
||||
/** This funcion selects or desselects all animes from selected to show */
|
||||
fun setAllAnimeSel(){
|
||||
var 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)
|
||||
db.execSQL("DELETE FROM ANIMESON")
|
||||
if (selectAll == false){ //Set all
|
||||
var animeIDs = getAllAnimeIDs()
|
||||
|
||||
for (pos in animeIDs){
|
||||
db.insert("ANIMESON",
|
||||
"IDAnime" to animeIDs[pos-1]) //Pos is a count, arrays start at 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** It returns if all animes are selected or not */
|
||||
fun getAllAnimeSel(): Boolean{
|
||||
var set = getCountAnimeSel();
|
||||
var countanime = getAllAnimeIDs().size;
|
||||
if (set == countanime){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/** It returns to program that this sentence can't be seen */
|
||||
fun getSentenceCanBeSeen(year: Int,month: Int, day: Int): Boolean {
|
||||
//TODO, return 0 when if check this sentence will be "nothing", for disable button
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Access property for Context
|
||||
val Context.database: SQLiteHelper
|
||||
get() = SQLiteHelper.getInstance(applicationContext)
|
||||
+896
-896
File diff suppressed because it is too large.
Load diff
@@ -1,2 +1,2 @@
|
||||
#Tue Aug 13 23:39:50 CEST 2019
|
||||
VERSION_CODE=1295
|
||||
#Sun Apr 07 19:54:23 CEST 2024
|
||||
VERSION_CODE=1354
|
||||
+38
-47
@@ -1,47 +1,38 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
//def kotlin_version = '1.3.21'
|
||||
classpath 'com.android.tools.build:gradle:3.4.2'
|
||||
//classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
//ext.kotlin_version = "$kotlin_version"
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.3.41'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
/*dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.41"
|
||||
}*/
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
maven { url 'https://jitpack.io' }
|
||||
maven {
|
||||
url "https://maven.google.com"
|
||||
}
|
||||
|
||||
google()
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.5.20'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
compileTestKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
jcenter()
|
||||
google()
|
||||
}
|
||||
}
|
||||
|
||||
+17
-17
@@ -1,18 +1,18 @@
|
||||
## Project-wide Gradle settings.
|
||||
#
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
#
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
# Default value: -Xmx1024m -XX:MaxPermSize=256m
|
||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
#
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
#Tue Nov 14 12:27:09 CET 2017
|
||||
android.enableJetifier=true
|
||||
android.useAndroidX=true
|
||||
## Project-wide Gradle settings.
|
||||
#
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
#
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
# Default value: -Xmx1024m -XX:MaxPermSize=256m
|
||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
#
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
#Tue Nov 14 12:27:09 CET 2017
|
||||
android.enableJetifier=true
|
||||
android.useAndroidX=true
|
||||
org.gradle.jvmargs=-Xmx1536m
|
||||
Vendored
BIN
Binary file not shown.
+1
-2
@@ -1,6 +1,5 @@
|
||||
#Tue Aug 13 22:31:54 CEST 2019
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
|
||||
@@ -1,74 +1,129 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
MAX_FD=maximum
|
||||
|
||||
warn ( ) {
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
} >&2
|
||||
|
||||
die ( ) {
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
@@ -77,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
@@ -85,76 +140,95 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
||||
function splitJvmOpts() {
|
||||
JVM_OPTS=("$@")
|
||||
}
|
||||
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
||||
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
Vendored
+89
-90
@@ -1,90 +1,89 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
Reference in new issue
Block a user