@@ -23,15 +23,23 @@ import androidx.core.view.WindowInsetsCompat
23
23
import com.google.android.material.button.MaterialButton
24
24
import com.google.android.material.dialog.MaterialAlertDialogBuilder
25
25
import com.google.android.material.elevation.SurfaceColors
26
+ import kotlinx.coroutines.CoroutineScope
27
+ import kotlinx.coroutines.Dispatchers
28
+ import kotlinx.coroutines.launch
29
+ import kotlinx.coroutines.runBlocking
26
30
import ru.dimon6018.neko11.NekoApplication.Companion.getNekoTheme
27
31
import ru.dimon6018.neko11.R
28
32
import ru.dimon6018.neko11.ui.fragments.NekoLandFragment
29
33
import ru.dimon6018.neko11.ui.fragments.NekoLandFragment.Companion.shareCat
30
34
import ru.dimon6018.neko11.workers.Cat
31
35
import ru.dimon6018.neko11.workers.Cat.Companion.create
36
+ import ru.dimon6018.neko11.workers.NekoWorker
32
37
import ru.dimon6018.neko11.workers.PrefState
33
38
34
39
class NekoAboutActivity : AppCompatActivity () {
40
+
41
+ private var imageViewCat: ImageView ? = null
42
+
35
43
override fun onCreate (savedInstanceState : Bundle ? ) {
36
44
setTheme(getNekoTheme(this ))
37
45
super .onCreate(savedInstanceState)
@@ -44,9 +52,10 @@ class NekoAboutActivity : AppCompatActivity() {
44
52
window.navigationBarColor = SurfaceColors .SURFACE_2 .getColor(this )
45
53
val github = findViewById<MaterialButton >(R .id.github_button)
46
54
val tg = findViewById<MaterialButton >(R .id.telegram_button)
55
+ imageViewCat = findViewById(R .id.imageViewCat)
47
56
github.setOnClickListener { openWeb(this , " https://github.com/queuejw/Neko11" ) }
48
57
tg.setOnClickListener { openWeb(this , " https://t.me/nekoapp_news" ) }
49
- setupCatImage()
58
+ setupCatImage(this )
50
59
val cord = findViewById<CoordinatorLayout >(R .id.coordinatorabout)
51
60
ViewCompat .setOnApplyWindowInsetsListener(cord) { v: View , insets: WindowInsetsCompat ->
52
61
val pB = insets.getInsets(WindowInsetsCompat .Type .navigationBars()).bottom
@@ -66,6 +75,10 @@ class NekoAboutActivity : AppCompatActivity() {
66
75
.setNegativeButton(android.R .string.cancel, null )
67
76
.show()
68
77
}
78
+ imageViewCat!! .setOnClickListener {
79
+ val mPrefs = PrefState (this )
80
+ NekoWorker .notifyCat(this , NekoWorker .getExistingCat(mPrefs), " ?????" )
81
+ }
69
82
}
70
83
@Deprecated(" Deprecated in Java" )
71
84
override fun onRequestPermissionsResult (requestCode : Int ,
@@ -82,15 +95,20 @@ class NekoAboutActivity : AppCompatActivity() {
82
95
return super .onOptionsItemSelected(item)
83
96
}
84
97
85
- private fun setupCatImage () {
86
- Thread {
87
- val cat: Cat = create(this )
88
- val bitmap = cat.createIconBitmap(NekoLandFragment .EXPORT_BITMAP_SIZE , NekoLandFragment .EXPORT_BITMAP_SIZE , 0 )
89
- runOnUiThread {
90
- val imageViewCat = findViewById<ImageView >(R .id.imageViewCat)
91
- imageViewCat.setImageBitmap(bitmap)
98
+ private fun setupCatImage (context : Context ) {
99
+ CoroutineScope (Dispatchers .IO ).launch {
100
+ val cat: Cat = create(context)
101
+ val bitmap = cat.createIconBitmap(
102
+ NekoLandFragment .EXPORT_BITMAP_SIZE ,
103
+ NekoLandFragment .EXPORT_BITMAP_SIZE ,
104
+ 0
105
+ )
106
+ runBlocking {
107
+ runOnUiThread {
108
+ imageViewCat?.setImageBitmap(bitmap)
109
+ }
92
110
}
93
- }.start()
111
+ }
94
112
}
95
113
private fun saveAllCatsToGallery (context : Context ) {
96
114
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
@@ -115,25 +133,25 @@ class NekoAboutActivity : AppCompatActivity() {
115
133
}
116
134
}
117
135
private fun saveAllCatsToGalleryContinue (context : Context ) {
118
- val mPrefs = PrefState (context)
119
- Thread {
120
- var pos = 0
121
- val max = PrefState (context).cats.size
122
- val list = mPrefs.cats
123
- while (pos != max) {
124
- val cat = list[pos]
125
- shareCat(this , cat, false )
126
- pos + = 1
136
+ CoroutineScope (Dispatchers .IO ).launch {
137
+ val mPrefs = PrefState (context)
138
+ val max = mPrefs.cats.size
139
+ val list = mPrefs.cats
140
+ for (i in 0 .. max) {
141
+ val cat = list[i]
142
+ shareCat(this @NekoAboutActivity, cat, false )
127
143
}
128
- runOnUiThread {
129
- MaterialAlertDialogBuilder (this )
144
+ runBlocking {
145
+ runOnUiThread {
146
+ MaterialAlertDialogBuilder (context)
130
147
.setIcon(AppCompatResources .getDrawable(context, R .drawable.ic_success))
131
148
.setTitle(R .string.save_title)
132
149
.setMessage(R .string.save_all_cats_done)
133
150
.setPositiveButton(android.R .string.ok, null )
134
151
.show()
152
+ }
135
153
}
136
- }.start()
154
+ }
137
155
}
138
156
companion object {
139
157
fun openWeb (activity : Activity , link : String? ) {
0 commit comments