Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

---update_to_target_sdk_34: #1112

Merged
merged 5 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ jobs:
name: test and assemble
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: set up JDK 11
uses: actions/setup-java@v1
- uses: actions/checkout@v3
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 11
java-version: 17
distribution: 'temurin'
- name: Generate dummy property file
run: |
echo "#Treetracker API Keys
Expand Down
41 changes: 20 additions & 21 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ def loadExtraProperties(String fileName) {
loadExtraProperties("treetracker.keys.properties")

android {
compileSdkVersion 31
buildToolsVersion '30.0.3'

compileSdkVersion 34
defaultConfig {
applicationId "org.greenstand.android.TreeTracker"
minSdkVersion 21
targetSdkVersion 31
targetSdkVersion 34
versionCode 196
versionName "2.1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -56,29 +54,25 @@ android {
buildFeatures {
compose true
viewBinding true

buildConfig = true
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11" //"1.8"
}

composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerExtensionVersion "1.5.14"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_11//VERSION_1_8
targetCompatibility JavaVersion.VERSION_11

coreLibraryDesugaringEnabled = true
}

lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}

buildTypes {
release {
Expand Down Expand Up @@ -170,11 +164,16 @@ android {
exclude 'META-INF/INDEX.LIST'

}
lint {
abortOnError false
checkReleaseBuilds false
}
namespace 'org.greenstand.android.TreeTracker'
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11" //"1.8"
}
}

Expand Down Expand Up @@ -215,7 +214,7 @@ dependencies {
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.animation:animation:$compose_version"
implementation "androidx.activity:activity-compose:1.3.0"
implementation "androidx.navigation:navigation-compose:2.4.1"
implementation "androidx.navigation:navigation-compose:2.5.0"

//Permissions management library for Jetpack Compose
implementation "com.google.accompanist:accompanist-permissions:0.21.1-beta"
Expand All @@ -228,11 +227,11 @@ dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")

//Database
implementation 'androidx.room:room-runtime:2.4.0-beta01'
implementation 'androidx.room:room-ktx:2.4.0-beta01'
kapt "androidx.room:room-compiler:2.4.0-beta01"
implementation 'androidx.room:room-runtime:2.6.1'
implementation 'androidx.room:room-ktx:2.6.1'
kapt "androidx.room:room-compiler:2.6.1"

devImplementation 'com.amitshekhar.android:debug-db:1.0.6'
devImplementation 'com.github.amitshekhariitbhu.Android-Debug-Database:debug-db:v1.0.6'

api "com.squareup.retrofit2:converter-gson:${retrofit2Version}"
implementation "com.squareup.retrofit2:retrofit:${retrofit2Version}"
Expand Down Expand Up @@ -263,7 +262,7 @@ dependencies {
implementation 'com.google.firebase:firebase-iid:21.0.1'

testImplementation 'androidx.test:core-ktx:1.5.0'
testImplementation "io.mockk:mockk:1.10.0"
testImplementation "io.mockk:mockk:1.13.12"
testImplementation "junit:junit:4.13.1"
testImplementation "androidx.room:room-testing:2.2.6"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.9"
Expand Down
19 changes: 15 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.greenstand.android.TreeTracker"
xmlns:tools="http://schemas.android.com/tools"
android:installLocation="auto">

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>-->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>

<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>


<uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove" />

<application
android:name=".application.TreeTrackerApplication"
android:allowBackup="true"
Expand All @@ -29,7 +37,10 @@
android:hardwareAccelerated="true">

<uses-library android:name="org.apache.http.legacy" android:required="false"/>

<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="dataSync"
tools:node="merge" />
<activity android:name=".activities.ImageCaptureActivity"
android:configChanges="orientation"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.greenstand.android.TreeTracker.application
import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.google.firebase.FirebaseApp
import org.greenstand.android.TreeTracker.BuildConfig
import org.greenstand.android.TreeTracker.analytics.ExceptionLogger
import org.greenstand.android.TreeTracker.api.ObjectStorageClient
Expand All @@ -27,6 +28,7 @@ import org.greenstand.android.TreeTracker.di.roomModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.startKoin
import org.koin.core.logger.Level
import timber.log.Timber

class TreeTrackerApplication : Application() {
Expand All @@ -35,11 +37,13 @@ class TreeTrackerApplication : Application() {
appContext = applicationContext

super.onCreate()
// FirebaseApp.initializeApp(appContext)

ObjectStorageClient.init(applicationContext)

startKoin {
androidLogger()
// androidLogger()
androidLogger(Level.NONE)
androidContext(applicationContext)
modules(
appModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.greenstand.android.TreeTracker.background
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.content.pm.ServiceInfo
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
Expand Down Expand Up @@ -49,7 +50,11 @@ class SyncNotificationManager(
.addAction(android.R.drawable.ic_delete, applicationContext.getString(R.string.cancel), intent)
.setProgress(0, 0, true)

return ForegroundInfo(NOTIFICATION_ID, builder.build())
return ForegroundInfo(NOTIFICATION_ID, builder.build(),if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_DATA_SYNC
} else {
0
})
}

@RequiresApi(Build.VERSION_CODES.O)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class TreeSyncWorker(
notificationManager.createNotificationChannel(channel)
}

val PENDING_INTENT_FLAG_MUTABLE = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0
val pendingFlag = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) PendingIntent.FLAG_MUTABLE else 0
val notification = NotificationCompat.Builder(applicationContext, NOTIFICATION_CHANNEL_ID)
.setContentIntent(PendingIntent.getActivity(applicationContext, 0, Intent(applicationContext, TreeTrackerActivity::class.java), PENDING_INTENT_FLAG_MUTABLE))
.setContentIntent(PendingIntent.getActivity(applicationContext, 0, Intent(applicationContext, TreeTrackerActivity::class.java), pendingFlag))
.setSmallIcon(R.drawable.upload_icon)
.setOngoing(true)
.setAutoCancel(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class TreeCaptureViewModel(
class TreeCaptureViewModelFactory(private val profilePicUrl: String) :
ViewModelProvider.Factory, KoinComponent {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
CaptureFlowScopeManager.open()
return TreeCaptureViewModel(profilePicUrl, get(), get(), get(), get(), get(), get()) as T
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class DashboardViewModel(
triggerSnackBar(R.string.sync_preparing)
_isSyncing = true
}

null -> {}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AnnouncementViewModelFactory(
) :
ViewModelProvider.Factory, KoinComponent {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return AnnouncementViewModel(messageId, get()) as T
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ChatViewModel(
class ChatViewModelFactory(private val userId: Long, private val otherChatIdentifier: String) :
ViewModelProvider.Factory, KoinComponent {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return ChatViewModel(userId, otherChatIdentifier, get(), get()) as T
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class IndividualMessageListViewModel(
class IndividualMessageListViewModelFactory(private val userId: Long) :
ViewModelProvider.Factory, KoinComponent {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return IndividualMessageListViewModel(userId, get(), get()) as T
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class SurveyViewModel(
class SurveyViewModelFactory(private val messageId: String) :
ViewModelProvider.Factory, KoinComponent {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return SurveyViewModel(messageId, get(), get()) as T
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import org.koin.core.component.get
@Suppress("UNCHECKED_CAST")
class TreeTrackerViewModelFactory : ViewModelProvider.NewInstanceFactory(), KoinComponent {

override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return when {
modelClass.isAssignableFrom(UserSelectViewModel::class.java) -> get<UserSelectViewModel>() as T
modelClass.isAssignableFrom(DashboardViewModel::class.java) -> get<DashboardViewModel>() as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class Preferences(
private val prefUpdateFlow: MutableSharedFlow<String> = MutableSharedFlow(replay = 1)
private val preferenceChangeListener: SharedPreferences.OnSharedPreferenceChangeListener =
SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
prefUpdateFlow.tryEmit(key)
if (key != null) {
prefUpdateFlow.tryEmit(key)
}
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.greenstand.android.TreeTracker.splash

import android.Manifest
import android.os.Build
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.Image
Expand Down Expand Up @@ -45,6 +46,20 @@ fun SplashScreen(
viewModel: SplashScreenViewModel = viewModel(factory = SplashScreenViewModelFactory(orgJsonString)),
navController: NavHostController = LocalNavHostController.current,
) {
val permissions = mutableListOf(
// Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
)


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
permissions.add(Manifest.permission.POST_NOTIFICATIONS)
}



val scope = rememberCoroutineScope()

val permissionRequester = rememberLauncherForActivityResult(
Expand All @@ -68,16 +83,8 @@ fun SplashScreen(
}
}
)

LaunchedEffect(true) {
permissionRequester.launch(
arrayOf(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION
)
)
permissionRequester.launch(permissions.toTypedArray())
}

Image(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SplashScreenViewModel(
class SplashScreenViewModelFactory(private val orgJsonString: String?) :
ViewModelProvider.Factory, KoinComponent {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return SplashScreenViewModel(orgJsonString, get(), get(), get(), get(), get(), get(), get(), get(), get()) as T
}
}
Loading
Loading