Skip to content

Commit 6f2773c

Browse files
committed
Gradle commit
Gradle commit
1 parent ab0d311 commit 6f2773c

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

app/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ android {
3737
sourceCompatibility JavaVersion.VERSION_11
3838
targetCompatibility JavaVersion.VERSION_11
3939
}
40+
41+
kotlinOptions {
42+
jvmTarget = "11"
43+
}
4044
}
4145

4246
dependencies {

app/src/main/java/com/bharathvishal/textfilegeneratorbenchmark/MainActivity.kt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import android.content.Context
55
import android.os.Bundle
66
import android.os.Handler
77
import android.os.Looper
8-
import android.os.Looper.*
98
import android.widget.LinearLayout
109
import android.widget.Toast
10+
import androidx.activity.OnBackPressedCallback
1111
import androidx.appcompat.app.AppCompatActivity
1212
import androidx.appcompat.widget.Toolbar
1313

@@ -47,25 +47,28 @@ class MainActivity : AppCompatActivity() {
4747
} catch (e: Exception) {
4848
e.printStackTrace()
4949
}
50-
}
51-
5250

53-
override fun onBackPressed() {
54-
//part to handle back press
55-
//executed when stack_top=-1 and activity recreated value is No
56-
Handler(Looper.getMainLooper()).postDelayed({
57-
mRunnableBackButton
58-
}, 1500)
59-
// 1.50 seconds in ms
6051

61-
62-
if (doubleBackToExitPressedOnce) {
63-
super.onBackPressed()
64-
return
65-
} else {
66-
showCustomToast("Please press BACK again to exit", activityContextMain!!)
67-
}
68-
doubleBackToExitPressedOnce = true
52+
onBackPressedDispatcher.addCallback(
53+
this, // lifecycle owner
54+
object : OnBackPressedCallback(true) {
55+
override fun handleOnBackPressed() {
56+
//part to handle back press
57+
//executed when stack_top=-1 and activity recreated value is No
58+
Handler(Looper.getMainLooper()).postDelayed({
59+
mRunnableBackButton
60+
}, 1500)
61+
// 1.50 seconds in ms
62+
63+
64+
if (doubleBackToExitPressedOnce) {
65+
finish()
66+
} else {
67+
showCustomToast("Please press BACK again to exit", activityContextMain!!)
68+
}
69+
doubleBackToExitPressedOnce = true
70+
}
71+
})
6972
}
7073

7174

app/src/main/java/com/bharathvishal/textfilegeneratorbenchmark/TextFileGeneratorFragment.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@file:Suppress("DEPRECATION")
2-
31
package com.bharathvishal.textfilegeneratorbenchmark
42

53
import android.annotation.SuppressLint

app/src/main/java/com/bharathvishal/textfilegeneratorbenchmark/Utilities.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Utilities {
1111
fun deleteFiles(curFile: File) {
1212
try {
1313
if (curFile.isDirectory)
14-
for (child in curFile.listFiles())
14+
for (child in curFile.listFiles()!!)
1515
deleteFiles(child)
1616

1717
curFile.delete()

0 commit comments

Comments
 (0)