Skip to content

Commit

Permalink
fix: Build errors due to old kotlin and gradle versions (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrsalah3 authored Apr 30, 2024
1 parent 27a8933 commit 0c9005a
Show file tree
Hide file tree
Showing 34 changed files with 612 additions and 460 deletions.
10 changes: 5 additions & 5 deletions BadgeMagicModule/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

}

val kt_serial = "0.14.0"
val kt_serial = "1.6.2"
val klockVersion = "1.8.6"

kotlin {
Expand All @@ -24,17 +24,17 @@ kotlin {

sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kt_serial")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kt_serial")
implementation("com.soywiz.korlibs.klock:klock:$klockVersion")
}

sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kt_serial")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kt_serial")
}

sourceSets["iosMain"].dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$kt_serial")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$kt_serial")
}
}

Expand Down Expand Up @@ -65,4 +65,4 @@ val packForXcode by tasks.creating(Sync::class) {
}
}

tasks.getByName("build").dependsOn(packForXcode)
tasks.getByName("build").dependsOn(packForXcode)
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.fossasia.badgemagic.helpers

import kotlinx.serialization.encodeToString
import org.fossasia.badgemagic.data.BadgeConfig
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonConfiguration

object JSONHelper {
fun decodeJSON(badgeJSON: String) = Json(JsonConfiguration.Stable).parse(BadgeConfig.serializer(),badgeJSON)
fun encodeJSON(badgeData: BadgeConfig) = Json(JsonConfiguration.Stable).stringify(BadgeConfig.serializer(),badgeData)
}
private val jsonFormat = Json { encodeDefaults = true }

fun decodeJSON(badgeJSON: String): BadgeConfig = Json.decodeFromString(badgeJSON)
fun encodeJSON(badgeData: BadgeConfig) = jsonFormat.encodeToString(badgeData)
}
7 changes: 2 additions & 5 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ plugins {
apply plugin: "com.github.b3er.local.properties"
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'

def KEYSTORE_FILE = rootProject.file('scripts/key.jks')
def TRAVIS_BUILD = System.getenv("TRAVIS") == "true" && KEYSTORE_FILE.exists()
def LOCAL_KEY_PRESENT = project.hasProperty('SIGNING_KEY_FILE') && rootProject.file(SIGNING_KEY_FILE).exists()

androidExtensions {
experimental = true
}

android {
compileSdkVersion versions.compileSdk
buildToolsVersion versions.buildTools
Expand Down Expand Up @@ -63,6 +59,7 @@ android {
}

buildFeatures.dataBinding = true
buildFeatures.viewBinding = true

packagingOptions {
pickFirst 'META-INF/kotlinx-serialization-runtime.kotlin_module'
Expand Down
12 changes: 7 additions & 5 deletions android/src/main/java/org/fossasia/badgemagic/BadgeMagicApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class BadgeMagicApp : Application() {
startKoin {
androidLogger()
androidContext(applicationContext)
modules(listOf(
singletonModules,
utilModules,
viewModelModules
))
modules(
listOf(
singletonModules,
utilModules,
viewModelModules
)
)
}

initLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,42 +84,42 @@ class SaveAdapter(private val context: Context?, private val list: List<ConfigIn
else -> ContextCompat.getDrawable(itemView.context, android.R.color.transparent)
}
text.setTextColor(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)
playPause.setColorFilter(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)
editButton.setColorFilter(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)
delete.setColorFilter(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)

transfer.setColorFilter(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)

export.setColorFilter(
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
when {
selectedPosition != -1 && selectedPosition == adapterPosition -> ContextCompat.getColor(itemView.context, android.R.color.white)
else -> ContextCompat.getColor(itemView.context, android.R.color.black)
}
)

val badge: BadgeConfig = JSONHelper.decodeJSON(item.badgeJSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ inline fun wtf(t: Throwable) = Timber.wtf(t)
/** @suppress */
@PublishedApi
internal inline fun log(block: () -> Unit) {
if (Timber.treeCount() > 0) block()
if (Timber.treeCount > 0) block()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import android.bluetooth.BluetoothManager
import android.bluetooth.BluetoothProfile
import android.content.Context
import android.content.Context.BLUETOOTH_SERVICE
import java.util.LinkedList
import org.fossasia.badgemagic.core.android.log.Timber
import org.fossasia.badgemagic.util.BadgeUtils
import org.fossasia.badgemagic.utils.ByteArrayUtils
import org.koin.core.KoinComponent
import org.koin.core.inject
import java.util.LinkedList

class GattClient : KoinComponent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ class ScanHelper : KoinComponent {
this.onDeviceFoundCallback = onDeviceFoundCallback
isScanning = true

val filters = listOf(ScanFilter.Builder()
.setServiceUuid(ParcelUuid(badgeUtils.currentDevice.serviceID))
.build())
val filters = listOf(
ScanFilter.Builder()
.setServiceUuid(ParcelUuid(badgeUtils.currentDevice.serviceID))
.build()
)

val settings = ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
Expand Down
20 changes: 12 additions & 8 deletions android/src/main/java/org/fossasia/badgemagic/data/badge/Badges.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package org.fossasia.badgemagic.data.badge
import java.util.UUID

enum class Badges(val device: DeviceID) {
LSLED(DeviceID(
UUID.fromString("0000fee0-0000-1000-8000-00805f9b34fb"),
UUID.fromString("0000fee1-0000-1000-8000-00805f9b34fb")
)),
VBLAB(DeviceID(
UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"),
UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb")
));
LSLED(
DeviceID(
UUID.fromString("0000fee0-0000-1000-8000-00805f9b34fb"),
UUID.fromString("0000fee1-0000-1000-8000-00805f9b34fb")
)
),
VBLAB(
DeviceID(
UUID.fromString("0000fff0-0000-1000-8000-00805f9b34fb"),
UUID.fromString("0000fff1-0000-1000-8000-00805f9b34fb")
)
);
}
50 changes: 30 additions & 20 deletions android/src/main/java/org/fossasia/badgemagic/ui/DrawerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import androidx.core.view.GravityCompat
import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.FragmentTransaction
import com.google.android.material.navigation.NavigationView
import kotlinx.android.synthetic.main.activity_drawer.*
import kotlinx.android.synthetic.main.app_bar_drawer.*
import org.fossasia.badgemagic.R
import org.fossasia.badgemagic.core.android.log.Timber
import org.fossasia.badgemagic.databinding.ActivityDrawerBinding
import org.fossasia.badgemagic.extensions.setRotation
import org.fossasia.badgemagic.ui.base.BaseActivity
import org.fossasia.badgemagic.ui.base.BaseFragment
Expand Down Expand Up @@ -53,12 +52,14 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi
private var isItemCheckedNew = false
private val storageUtils: StorageUtils by inject()

private lateinit var binding: ActivityDrawerBinding

private val viewModel by viewModel<DrawerViewModel>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_drawer)
binding = ActivityDrawerBinding.inflate(layoutInflater)
setContentView(binding.root)

if (intent.action == Intent.ACTION_VIEW)
importFile(intent)
Expand All @@ -75,7 +76,7 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi
private fun setDefaultFragment() {
if (supportFragmentManager.findFragmentById(R.id.frag_container) == null) {
switchFragment(TextArtFragment())
nav_view.setCheckedItem(R.id.create)
binding.navView.setCheckedItem(R.id.create)
}
}

Expand All @@ -86,29 +87,32 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi
supportFragmentManager.beginTransaction()
.replace(R.id.frag_container, clipart)
.commit()
nav_view.setCheckedItem(R.id.saved_cliparts)
binding.navView.setCheckedItem(R.id.saved_cliparts)
} else if (bundle?.getString("badge").equals("badge")) {
val badge = SavedBadgesFragment()
supportFragmentManager.beginTransaction()
.replace(R.id.frag_container, badge)
.commit()
nav_view.setCheckedItem(R.id.saved_badges)
binding.navView.setCheckedItem(R.id.saved_badges)
}
}

private fun setupDrawerAndToolbar() {
setSupportActionBar(toolbar)
setSupportActionBar(binding.appBar.toolbar)

val toggle = ActionBarDrawerToggle(
this, drawer_layout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close)
drawer_layout.addDrawerListener(toggle)
this, binding.drawerLayout, binding.appBar.toolbar,
R.string.navigation_drawer_open,
R.string.navigation_drawer_close
)
binding.drawerLayout.addDrawerListener(toggle)
toggle.syncState()

Timber.e {
"OnCreate, ${viewModel.swappingOrientation}"
}

drawer_layout.addDrawerListener(object : DrawerLayout.DrawerListener {
binding.drawerLayout.addDrawerListener(object : DrawerLayout.DrawerListener {
override fun onDrawerStateChanged(newState: Int) {
}

Expand Down Expand Up @@ -178,23 +182,23 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi
}
})

nav_view.setNavigationItemSelectedListener(this)
binding.navView.setNavigationItemSelectedListener(this)
if (!viewModel.swappingOrientation)
when (intent.action) {
"org.fossasia.badgemagic.createBadge.shortcut" -> {
switchFragment(TextArtFragment.newInstance())
showMenu?.setGroupVisible(R.id.saved_group, false)
nav_view.setCheckedItem(R.id.create)
binding.navView.setCheckedItem(R.id.create)
}
"org.fossasia.badgemagic.savedBadges.shortcut" -> {
switchFragment(SavedBadgesFragment.newInstance())
showMenu?.setGroupVisible(R.id.saved_group, true)
nav_view.setCheckedItem(R.id.saved_badges)
binding.navView.setCheckedItem(R.id.saved_badges)
}
} else {
switchFragment(DrawFragment.newInstance())
showMenu?.setGroupVisible(R.id.saved_group, false)
nav_view.setCheckedItem(R.id.draw)
binding.navView.setCheckedItem(R.id.draw)
}
}

Expand All @@ -212,7 +216,7 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi
setRotation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
switchFragment(DrawFragment.newInstance())
showMenu?.setGroupVisible(R.id.saved_group, false)
nav_view.setCheckedItem(R.id.draw)
binding.navView.setCheckedItem(R.id.draw)
}

private fun prepareForScan() {
Expand All @@ -231,8 +235,13 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi
private fun showImportDialog(uri: Uri?) {
AlertDialog.Builder(this)
.setTitle(getString(R.string.import_dialog))
.setMessage("${getString(R.string.import_dialog_message)} ${storageUtils.getFileName(this, uri
?: Uri.EMPTY)}")
.setMessage(
"${getString(R.string.import_dialog_message)} ${storageUtils.getFileName(
this,
uri
?: Uri.EMPTY
)}"
)
.setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int ->
if (!storageUtils.checkIfFilePresent(this, uri)) {
saveImportFile(uri)
Expand Down Expand Up @@ -271,13 +280,14 @@ class DrawerActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedLi
private fun switchFragment(fragment: BaseFragment) {
supportFragmentManager.beginTransaction()
.replace(R.id.frag_container, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
}

private fun checkManifestPermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
) {
Timber.i { "Coarse permission granted" }
} else {
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_PERMISSION_CODE)
Expand Down
Loading

0 comments on commit 0c9005a

Please sign in to comment.