Skip to content

Commit f18f630

Browse files
committed
fix: it compiles again
1 parent e5b0397 commit f18f630

21 files changed

+196
-1253
lines changed

android-sample/app/build.gradle.kts

+55-43
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,69 @@
11
plugins {
2-
// Application Specific Plugins
3-
id(BuildPlugins.androidApplication)
4-
id(BuildPlugins.kotlinAndroid)
5-
id(BuildPlugins.kotlinAndroidExtensions)
6-
7-
// Internal Script plugins
8-
id(ScriptPlugins.variants)
9-
id(ScriptPlugins.quality)
10-
id(ScriptPlugins.compilation)
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
114
}
125

136
android {
14-
compileSdkVersion(AndroidSdk.compile)
7+
namespace = "com.fernandocejas.sample"
158

9+
compileSdk = 33
1610
defaultConfig {
17-
minSdkVersion(AndroidSdk.min)
18-
targetSdkVersion(AndroidSdk.target)
11+
applicationId = "com.fernandocejas.sample"
12+
minSdk = 29
13+
targetSdk = 33
14+
versionCode = 1
15+
versionName = "1.0"
1916

20-
applicationId = AndroidClient.appId
21-
versionCode = AndroidClient.versionCode
22-
versionName = AndroidClient.versionName
23-
testInstrumentationRunner = AndroidClient.testRunner
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
19+
// See: 'variants.gradle.kts' if you want to configure the ndk block
20+
// for each product flavor in your build configuration.
21+
ndk {
22+
// Specifies the ABI configurations of your native
23+
// libraries Gradle should build and package with your APK.
24+
// Here is a list of supported abis:
25+
// https://developer.android.com/ndk/guides/abis
26+
abiFilters.addAll(
27+
setOf(
28+
"armeabi-v7a",
29+
"arm64-v8a",
30+
"x86",
31+
"x86_64"
32+
)
33+
)
34+
}
35+
}
36+
37+
compileOptions {
38+
sourceCompatibility = JavaVersion.VERSION_17
39+
targetCompatibility = JavaVersion.VERSION_17
40+
}
41+
42+
kotlinOptions {
43+
jvmTarget = JavaVersion.VERSION_17.toString()
44+
}
45+
46+
buildFeatures {
47+
viewBinding = true
2448
}
2549

26-
sourceSets {
27-
map { it.java.srcDir("src/${it.name}/kotlin") }
50+
buildTypes {
51+
getByName("debug") {
52+
isMinifyEnabled = false
53+
}
54+
getByName("release") {
55+
isMinifyEnabled = false
56+
}
2857
}
2958
}
3059

3160
dependencies {
32-
// Application dependencies
33-
implementation(Libraries.kotlinStdLib)
34-
implementation(Libraries.kotlinCoroutines)
35-
implementation(Libraries.kotlinCoroutinesAndroid)
36-
implementation(Libraries.ktxCore)
37-
implementation(Libraries.appCompat)
38-
implementation(Libraries.fragment)
39-
implementation(Libraries.material)
40-
implementation(Libraries.constraintLayout)
41-
42-
// Unit/Android tests dependencies
43-
testImplementation(TestLibraries.junit4)
44-
testImplementation(TestLibraries.mockk)
45-
testImplementation(TestLibraries.kluent)
46-
testImplementation(TestLibraries.robolectric)
47-
48-
// Acceptance tests dependencies
49-
androidTestImplementation(TestLibraries.testRunner)
50-
androidTestImplementation(TestLibraries.espressoCore)
51-
androidTestImplementation(TestLibraries.testExtJunit)
52-
androidTestImplementation(TestLibraries.testRules)
53-
androidTestImplementation(TestLibraries.espressoIntents)
54-
55-
// Development dependencies
56-
debugImplementation(DevLibraries.leakCanary)
61+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22")
62+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2")
63+
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.2")
64+
implementation("androidx.core:core-ktx:1.10.1")
65+
implementation("androidx.appcompat:appcompat:1.6.1")
66+
implementation("androidx.fragment:fragment-ktx:1.6.0")
67+
implementation("com.google.android.material:material:1.9.0")
68+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
5769
}

android-sample/app/src/androidTest/kotlin/com/fernandocejas/sample/AcceptanceTest.kt

-36
This file was deleted.

android-sample/app/src/main/AndroidManifest.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
android:roundIcon="@mipmap/ic_launcher_round"
1111
android:theme="@style/Theme.Main">
1212

13-
<activity android:name="com.fernandocejas.sample.MainActivity">
13+
<activity
14+
android:name="com.fernandocejas.sample.MainActivity"
15+
android:exported="true">
1416
<intent-filter>
1517
<action android:name="android.intent.action.MAIN" />
1618
<category android:name="android.intent.category.LAUNCHER" />

android-sample/app/src/main/kotlin/com/fernandocejas/sample/AndroidApplication.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class AndroidApplication : Application() {
3131
* The name passed as argument () maps to the
3232
* original library name in our Rust project
3333
*/
34-
// System.loadLibrary("cryptor_jni")
35-
System.loadLibrary("libcryptor_jni")
34+
System.loadLibrary("cryptor_jni")
3635
}
3736
}

android-sample/app/src/main/kotlin/com/fernandocejas/sample/MainActivity.kt

+36-4
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,40 @@
1515
*/
1616
package com.fernandocejas.sample
1717

18-
import com.fernandocejas.sample.core.platform.BaseActivity
18+
import android.os.Bundle
19+
import android.view.View
20+
import androidx.appcompat.app.AppCompatActivity
21+
import androidx.appcompat.widget.Toolbar
22+
import androidx.fragment.app.commit
23+
import com.fernandocejas.sample.databinding.ActivityLayoutBinding
1924

20-
class MainActivity : BaseActivity() {
21-
override fun fragment() = MainFragment()
22-
}
25+
class MainActivity : AppCompatActivity() {
26+
27+
private lateinit var binding: ActivityLayoutBinding
28+
override fun onCreate(savedInstanceState: Bundle?) {
29+
super.onCreate(savedInstanceState)
30+
31+
binding = ActivityLayoutBinding.inflate(layoutInflater)
32+
33+
setContentView(binding.root)
34+
setupToolbar()
35+
addFragment(savedInstanceState)
36+
}
37+
38+
private fun setupToolbar() {
39+
val toolbar = findViewById<View>(R.id.toolbar) as Toolbar
40+
toolbar.title = getString(R.string.app_name)
41+
setSupportActionBar(toolbar)
42+
}
43+
44+
private fun addFragment(savedInstanceState: Bundle?) {
45+
if (firstTimeCreated(savedInstanceState)) {
46+
supportFragmentManager.commit {
47+
setReorderingAllowed(true)
48+
add(R.id.fragment_container_view, MainFragment())
49+
}
50+
}
51+
}
52+
53+
private fun firstTimeCreated(savedInstanceState: Bundle?) = savedInstanceState == null
54+
}

android-sample/app/src/main/kotlin/com/fernandocejas/sample/MainFragment.kt

+45-15
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,66 @@
1616
package com.fernandocejas.sample
1717

1818
import android.os.Bundle
19+
import android.view.LayoutInflater
1920
import android.view.View
21+
import android.view.ViewGroup
2022
import android.widget.EditText
23+
import android.widget.Toast
24+
import androidx.fragment.app.Fragment
2125
import com.fernandocejas.rust.Cryptor
22-
import com.fernandocejas.sample.core.platform.BaseFragment
23-
import kotlinx.android.synthetic.main.fragment_main.*
26+
import com.fernandocejas.sample.core.extension.inputManager
27+
import com.fernandocejas.sample.databinding.FragmentMainBinding
2428

25-
class MainFragment : BaseFragment(R.layout.fragment_main) {
29+
class MainFragment : Fragment() {
30+
31+
private var _binding: FragmentMainBinding? = null
32+
private val binding get() = _binding!!
33+
34+
private val actionBar = activity?.actionBar
2635

2736
private val cryptor = Cryptor()
2837

38+
override fun onCreateView(
39+
inflater: LayoutInflater,
40+
container: ViewGroup?,
41+
savedInstanceState: Bundle?
42+
): View {
43+
_binding = FragmentMainBinding.inflate(inflater, container, false)
44+
return binding.root
45+
}
46+
2947
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
3048
super.onViewCreated(view, savedInstanceState)
3149
initializeUI()
3250
}
3351

52+
override fun onDestroyView() {
53+
super.onDestroyView()
54+
_binding = null
55+
}
56+
3457
private fun initializeUI() {
35-
btn_encrypt.setOnClickListener { onButtonEncryptClicked() }
36-
btn_decrypt.setOnClickListener { onButtonDecryptClicked() }
58+
binding.btnEncrypt.setOnClickListener { onButtonEncryptClicked() }
59+
binding.btnDecrypt.setOnClickListener { onButtonDecryptClicked() }
3760
}
3861

62+
3963
private fun onButtonEncryptClicked() {
40-
validateInput(edit_encrypt) {
41-
hideKeyboard(edit_encrypt)
42-
val encryptedText = cryptor.encrypt(edit_encrypt.text.toString())
64+
validateInput(binding.editEncrypt) {
65+
hideKeyboard(binding.editEncrypt)
66+
val encryptedText = cryptor.encrypt(binding.editEncrypt.text.toString())
4367
val successMsg = getString(R.string.txt_encrypted).plus(": ").plus(encryptedText)
44-
printResult(edit_decrypt, encryptedText)
68+
printResult(binding.editDecrypt, encryptedText)
4569
notifySuccess(successMsg)
4670
}
4771
}
4872

4973
private fun onButtonDecryptClicked() {
50-
validateInput(edit_decrypt) {
51-
hideKeyboard(edit_decrypt)
52-
val decryptedText = cryptor.decrypt(edit_decrypt.text.toString())
74+
validateInput(binding.editDecrypt) {
75+
hideKeyboard(binding.editDecrypt)
76+
val decryptedText = cryptor.decrypt(binding.editDecrypt.text.toString())
5377
val successMsg = getString(R.string.txt_decrypted).plus(": ").plus(decryptedText)
54-
printResult(edit_encrypt, decryptedText)
78+
printResult(binding.editEncrypt, decryptedText)
5579
notifySuccess(successMsg)
5680
}
5781
}
@@ -72,9 +96,15 @@ class MainFragment : BaseFragment(R.layout.fragment_main) {
7296

7397

7498
private fun notifySuccess(message: String) {
75-
edit_result.text.clear()
76-
edit_result.text.append(message)
99+
binding.editResult.text.clear()
100+
binding.editResult.text.append(message)
77101
toast(message)
78102
}
103+
104+
private fun hideKeyboard(view: View) =
105+
view.let { context?.inputManager?.hideSoftInputFromWindow(it.windowToken, 0) }
106+
107+
private fun toast(message: String) =
108+
Toast.makeText(activity, message.trim(), Toast.LENGTH_SHORT).show()
79109
}
80110

android-sample/app/src/main/kotlin/com/fernandocejas/sample/core/extension/Fragment.kt

-21
This file was deleted.

android-sample/app/src/main/kotlin/com/fernandocejas/sample/core/platform/BaseActivity.kt

-52
This file was deleted.

0 commit comments

Comments
 (0)