Skip to content
Snippets Groups Projects
Commit c1e9cd33 authored by benjamin.sitbon's avatar benjamin.sitbon
Browse files

rendu

parent 17845d52
No related branches found
No related tags found
No related merge requests found
Showing
with 563 additions and 0 deletions
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.1734375" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/drawable/ic_baseline_directions_walk_24.xml" value="0.3828125" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/drawable/ic_baseline_map_24.xml" value="0.1734375" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/drawable/ic_launcher_background.xml" value="0.1734375" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/drawable/map_black.xml" value="0.1734375" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/drawable/marker.xml" value="0.22135416666666666" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/drawable/walk.xml" value="0.22135416666666666" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/drawable/walk_black.xml" value="0.1734375" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/layout/activity_maps.xml" value="0.34057971014492755" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/layout/add_marker_dialog.xml" value="0.36666666666666664" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/layout/fragment_map.xml" value="0.33" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/layout/fragment_rando.xml" value="0.36666666666666664" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/layout/fragment_randon.xml" value="0.36666666666666664" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/layout/item_run.xml" value="0.31657608695652173" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/layout/main_fragment.xml" value="0.25" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/layout/rando_activity.xml" value="0.34057971014492755" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/layout/save.xml" value="0.28541666666666665" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/menu/menu.xml" value="0.5" />
<entry key="..\:/Users/benja/AndroidStudioProjects/RandoTracker/app/src/main/res/menu/menu_bottom_nav.xml" value="0.35260416666666666" />
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
/build
\ No newline at end of file
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
apply plugin: 'kotlin-kapt'
apply plugin: 'com.android.application'
apply plugin: 'dagger.hilt.android.plugin'
android {
compileSdk 31
defaultConfig {
applicationId "com.example.randotracker"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
// Activity KTX for viewModels()
implementation "androidx.activity:activity-ktx:1.4.0"
// Dagger - Hilt
implementation 'com.google.dagger:hilt-android:2.39.1'
kapt 'com.google.dagger:hilt-compiler:2.39.1'
kapt "androidx.room:room-compiler:2.4.1"
implementation 'androidx.room:room-common:2.4.1'
implementation 'androidx.room:room-ktx:2.4.1'
implementation 'androidx.fragment:fragment-ktx:1.4.1'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'com.google.android.gms:play-services-maps:18.0.2'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
implementation 'androidx.navigation:navigation-runtime-ktx:2.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.gms:play-services-location:19.0.1'
implementation 'androidx.lifecycle:lifecycle-service:2.4.0'
implementation 'javax.inject:javax.inject:1'
implementation 'junit:junit:4.13.2'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
testImplementation 'junit:junit:'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.google.dagger:hilt-android:2.40.5'
kapt 'com.google.dagger:hilt-compiler:2.40.5'
// For instrumentation tests
androidTestImplementation 'com.google.dagger:hilt-android-testing:2.40.5'
kaptAndroidTest 'com.google.dagger:hilt-compiler:2.40.5'
// For local unit tests
testImplementation 'com.google.dagger:hilt-android-testing:2.40.5'
kaptTest 'com.google.dagger:hilt-compiler:2.40.5'
}
kapt {
correctErrorTypes true
}
\ No newline at end of file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
\ No newline at end of file
package com.example.randotracker
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.randotracker", appContext.packageName)
}
}
\ No newline at end of file
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=47:20:1E:37:B4:EB:31:C6:E5:19:C3:DC:30:6C:F3:86:A9:DD:94:26%3Bcom.example.randotracker
You can also add your credentials to an existing key, using these values:
Package name:
com.example.randotracker
SHA-1 certificate fingerprint:
47:20:1E:37:B4:EB:31:C6:E5:19:C3:DC:30:6C:F3:86:A9:DD:94:26
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">AIzaSyA4XEr53RNiJ40hSYSJJ4d-5nDUZGK8Bbc</string>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.randotracker">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<application
android:name =".MainActi"
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/Theme.RandoTracker"
tools:ignore="AllowBackup">
<service
android:name=".service.NavigationService"
android:enabled="true"
android:exported="false" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".Randonne"
android:exported="true"
android:label="Rando">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
package com.example.randotracker
import android.content.Context
import androidx.room.Room
import com.example.randotracker.database.RandoDb
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object AppModule {
@Singleton
@Provides
fun provideRandoDatabase(
@ApplicationContext app: Context
) = Room.databaseBuilder(
app,
RandoDb::class.java,
"RandoDb"
).build()
@Singleton
@Provides
fun provideRunDB(db: RandoDb) = db.getDB()
}
\ No newline at end of file
package com.example.randotracker
object Constants {
const val NOTIFICATION_CHANNEL_ID = "Walker_channel"
const val NOTIFICATION_CHANNEL_NAME = "Walker"
const val NOTIFICATION_ID = 1
const val ACTION_START_OR_RESUME_SERVICE = "ACTION_START_OR_RESUME_SERVICE"
const val ACTION_PAUSE_SERVICE = "ACTION_START_OR_RESUME_SERVICE"
const val ACTION_STOP_SERVICE = "ACTION_START_OR_RESUME_SERVICE"
const val LOCATION_UPDATE_INTERVAL = 3000L
const val SHORTEST_UPDATE_INTERVAL = 2000L
}
\ No newline at end of file
package com.example.randotracker
class Data constructor(t: String, tim: Long, dist: Int) {
var title: String = t
var time: Long = tim
var distance: Int = dist
}
\ No newline at end of file
package com.example.randotracker
import android.app.Application
import androidx.room.Room
import com.example.randotracker.database.RandoDb
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class MainActi: Application() {
override fun onCreate() {
super.onCreate()
}
}
\ No newline at end of file
package com.example.randotracker
import androidx.lifecycle.*
import com.example.randotracker.database.RandoTable
import com.example.randotracker.service.NavigationService
import com.example.randotracker.ui.main.Requests
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class RandoViewModel @Inject constructor(
private val req: Requests,
) : ViewModel(){
val isTracking = NavigationService.isTracking
val pathPoints = NavigationService.pathPoints
val randos = MediatorLiveData<List<RandoTable>>()
fun deleteRando(rando: RandoTable) {
viewModelScope.launch {
req.deleteRando(rando)
}
}
fun insertRando(rando: RandoTable) {
viewModelScope.launch {
req.insertRando(rando)
}
}
/*fun getAllRandos() {
viewModelScope.launch {
var l: ArrayList<RandoTable> = ArrayList<RandoTable>()
for(item in req.getAllRandos().value!!) {
l.add(item)
}
randos.postValue(l)
}
}
init {
randos.addSource(req.getAllRandos()){res ->
res.let { randos.value = it }
}
}*/
}
package com.example.randotracker
import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.annotation.RequiresApi
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.room.Room
import com.example.randotracker.database.RandoRequest
import com.example.randotracker.fragments.MapFragment
import com.example.randotracker.databinding.RandoActivityBinding
import com.example.randotracker.fragments.Randon
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
@AndroidEntryPoint
class Randonne : AppCompatActivity() {
@Inject
lateinit var Db:RandoRequest
private val mapFrag = MapFragment()
private val randonFrag = Randon()
private lateinit var binding : RandoActivityBinding;
@RequiresApi(Build.VERSION_CODES.Q)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = RandoActivityBinding.inflate(layoutInflater)
setContentView(binding.root)
switchFragment(randonFrag)
binding.bottomNavigation.setOnItemSelectedListener {
when(it.itemId){
R.id.walk -> {
switchFragment(randonFrag)
it.setIcon(R.drawable.walk_black)
}
R.id.map -> {
switchFragment(mapFrag)
it.setIcon(R.drawable.map_black)
}
}
true
}
requestPermission(Manifest.permission.ACCESS_FINE_LOCATION)
requestPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
requestPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
//ContextCompat.startForegroundService(this, Intent(this, NavigationService::class.java))
}
private fun switchFragment(fragment : Fragment){
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.container,fragment)
transaction.commit()
}
fun hasPermission(permission:String) = ContextCompat.checkSelfPermission(this,permission)==PackageManager.PERMISSION_GRANTED
fun requestPermission(permission: String){
if(!hasPermission(permission)){
ActivityCompat.requestPermissions(this, arrayOf(permission),0)
}
}
}
\ No newline at end of file
package com.example.randotracker.adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.randotracker.Data
import com.example.randotracker.R
import com.example.randotracker.database.RandoTable
import com.google.android.material.textview.MaterialTextView
import java.util.*
import kotlin.collections.ArrayList
class RandoAdapter(private var itemList: ArrayList<Data>) : RecyclerView.Adapter<RandoAdapter.RandoViewHolder>() {
class RandoViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView){
val title:MaterialTextView = itemView.findViewById<MaterialTextView>(R.id.tvTitle)
val distance:MaterialTextView = itemView.findViewById<MaterialTextView>(R.id.tvTime)
val time:MaterialTextView = itemView.findViewById<MaterialTextView>(R.id.tvDistance)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RandoViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.item_run,parent,false)
return RandoViewHolder(itemView)
}
override fun onBindViewHolder(holder: RandoViewHolder, position: Int) {
val currentItem = itemList[position]
holder.title.setText(currentItem.title)
holder.distance.setText(currentItem.distance.toString())
holder.time.setText(currentItem.time.toString())
}
fun submitItems(newItem: Data){
itemList.add(newItem)
}
override fun getItemCount(): Int {
return itemList.size
}
}
\ No newline at end of file
package com.example.randotracker.database
import androidx.room.Database
import androidx.room.RoomDatabase
@Database(
entities = [RandoTable::class],
version = 1
)
abstract class RandoDb : RoomDatabase() {
abstract fun getDB(): RandoRequest
}
\ No newline at end of file
package com.example.randotracker.database
import androidx.lifecycle.LiveData
import androidx.room.*
@Dao
interface RandoRequest {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertRando(run: RandoTable)
@Delete
suspend fun deleteRando(run: RandoTable)
@Query("SELECT * FROM rando_table")
fun getAllRandos(): LiveData<List<RandoTable>>
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment