-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tharyck Gusmao
committed
Jun 20, 2022
1 parent
0f61e06
commit d5c7ee1
Showing
8 changed files
with
142 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
android/fitnesstracker/app/src/main/java/com/fitnesstracker/SqlHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.fitnesstracker | ||
|
||
import android.content.ContentValues | ||
import android.content.Context | ||
import android.database.sqlite.SQLiteDatabase | ||
import android.database.sqlite.SQLiteOpenHelper | ||
import android.util.Log | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
class SqlHelper(private val context: Context): | ||
SQLiteOpenHelper(context,DATABASE_NAME,null,DATABASE_VERSION) { | ||
|
||
companion object { | ||
private const val DATABASE_VERSION = 2 | ||
private const val DATABASE_NAME = "data" | ||
} | ||
private lateinit var INSTANCE: SqlHelper; | ||
// fun getInstance(context:Context):SqlHelper{ | ||
// if(INSTANCE==null){ | ||
// INSTANCE = SqlHelper(context); | ||
// } | ||
// return INSTANCE | ||
// } | ||
|
||
override fun onCreate(db: SQLiteDatabase?) { | ||
if (db != null) { | ||
db.execSQL( | ||
"CREATE TABLE calc (id INTEGER primary key, type_calc TEXT, res DECIMAL, created_date DATETIME)" | ||
) | ||
} | ||
} | ||
|
||
override fun onUpgrade(p0: SQLiteDatabase?, p1: Int, p2: Int) { | ||
Log.d("Teste","Upgrade disparado") | ||
} | ||
|
||
fun addItem(type:String,response:Double):Long{ | ||
val db:SQLiteDatabase = writableDatabase | ||
|
||
val calcId:Long = 0; | ||
try { | ||
db.beginTransaction() | ||
val values = ContentValues(); | ||
values.put("type_calc",type); | ||
values.put("res",response); | ||
|
||
val formatDate = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale("pt","BR")) | ||
val now = formatDate.format(Date()) | ||
values.put("created_date",now); | ||
db.insertOrThrow("calc",null,values) | ||
db.setTransactionSuccessful() | ||
|
||
}catch (e:Exception ){ | ||
Log.e("SQLite",e.message,e) | ||
|
||
}finally { | ||
if(db.isOpen){ | ||
db.endTransaction() | ||
} | ||
} | ||
|
||
return calcId | ||
|
||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
android/fitnesstracker/app/src/main/java/com/fitnesstracker/TmbActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.fitnesstracker | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
|
||
class TmbActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_tmb) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
android/fitnesstracker/app/src/main/res/layout/activity_tmb.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".TmbActivity"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
android/fitnesstracker/gradle/wrapper/gradle-wrapper.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Sun Jun 19 13:12:15 BRT 2022 | ||
#Sun Jun 19 21:01:34 BRT 2022 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |