Skip to content

Commit bae8afb

Browse files
committed
0.8.3
1 parent 85ea0f5 commit bae8afb

11 files changed

Lines changed: 166 additions & 39 deletions

File tree

.idea/deploymentTargetDropDown.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ android {
77
namespace 'ru.dimon6018.neko11'
88
compileSdk 34
99

10+
buildFeatures {
11+
buildConfig = true
12+
}
1013
defaultConfig {
1114
applicationId "ru.dimon6018.neko11"
1215
minSdk 23
1316
targetSdk 34
1417
versionCode 10
15-
versionName "0.8.2-reborn-neko11-compatibility"
16-
18+
versionName "0.8.3-reborn-neko11-compatibility"
1719
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1820
}
19-
2021
buildTypes {
2122
release {
2223
minifyEnabled true

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Copyright (C) 2016 The Android Open Source Project
2626
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
2727

2828
<application
29+
android:name=".NekoApp"
2930
android:label="@string/app_name"
3031
android:icon="@mipmap/icon"
3132
android:theme="@style/Theme.Neko7">
@@ -49,6 +50,11 @@ Copyright (C) 2016 The Android Open Source Project
4950
android:theme="@android:style/Theme.Material.Light.Dialog.NoActionBar"
5051
android:showOnLockScreen="true" />
5152

53+
<activity
54+
android:name=".NekoCrash"
55+
android:exported="true"
56+
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar" />
57+
5258
<!-- The quick settings tile, disabled by default -->
5359
<service
5460
android:name=".NekoTile"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ru.dimon6018.neko11
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.util.Log
6+
7+
class CrashHandler : Thread.UncaughtExceptionHandler {
8+
9+
private var cntxt: Context? = null
10+
11+
fun setContext(context: Context?) {
12+
cntxt = context
13+
}
14+
override fun uncaughtException(t: Thread, e: Throwable) {
15+
Log.e("Neko11", "Detected critical error. See: ${e.stackTraceToString()}")
16+
openErrorActivity(e)
17+
}
18+
private fun openErrorActivity(e: Throwable) {
19+
val startAppIntent = Intent(cntxt, NekoCrash::class.java)
20+
startAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
21+
startAppIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
22+
startAppIntent.putExtra("stacktrace",e.stackTraceToString())
23+
cntxt?.startActivity(startAppIntent)
24+
}
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.dimon6018.neko11
2+
3+
import android.app.Application
4+
5+
class NekoApp: Application() {
6+
override fun onCreate() {
7+
val crashHandler = CrashHandler()
8+
crashHandler.setContext(applicationContext)
9+
Thread.setDefaultUncaughtExceptionHandler(crashHandler)
10+
super.onCreate()
11+
}
12+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package ru.dimon6018.neko11
2+
3+
import android.content.ClipData
4+
import android.content.ClipboardManager
5+
import android.content.DialogInterface
6+
import android.os.Build
7+
import android.os.Bundle
8+
import androidx.appcompat.app.AppCompatActivity
9+
import com.google.android.material.button.MaterialButton
10+
import com.google.android.material.dialog.MaterialAlertDialogBuilder
11+
12+
class NekoCrash: AppCompatActivity() {
13+
override fun onCreate(savedInstanceState: Bundle?) {
14+
super.onCreate(savedInstanceState)
15+
setContentView(R.layout.neko_crash)
16+
val copy = findViewById<MaterialButton>(R.id.buttonCopy)
17+
val show = findViewById<MaterialButton>(R.id.buttonShow)
18+
val model = "Model: " + Build.MODEL + "\n"
19+
val brand = "Brand: " + Build.BRAND + "\n"
20+
val error = "Detected critical error.\n " + model + brand + intent.extras?.getString("stacktrace")
21+
show.setOnClickListener {
22+
MaterialAlertDialogBuilder(this)
23+
.setMessage(error)
24+
.setNegativeButton(R.string.copy
25+
) { _: DialogInterface?, _: Int -> copyError(error) }
26+
.setPositiveButton(android.R.string.ok, null)
27+
.show()
28+
}
29+
copy.setOnClickListener {
30+
copyError(error)
31+
}
32+
}
33+
private fun copyError(code: String) {
34+
val clipbrd = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
35+
val clip = ClipData.newPlainText("error", code)
36+
clipbrd.setPrimaryClip(clip)
37+
}
38+
}

app/src/main/java/ru/dimon6018/neko11/NekoLand.kt

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,26 @@ import androidx.recyclerview.widget.GridLayoutManager
4949
import androidx.recyclerview.widget.RecyclerView
5050
import com.google.android.material.dialog.MaterialAlertDialogBuilder
5151
import kotlinx.coroutines.CoroutineScope
52-
import kotlinx.coroutines.Deferred
5352
import kotlinx.coroutines.Dispatchers
54-
import kotlinx.coroutines.async
5553
import kotlinx.coroutines.cancel
5654
import kotlinx.coroutines.launch
57-
import kotlinx.coroutines.runBlocking
5855
import ru.dimon6018.neko11.NekoService.Companion.setupNotificationChannels
5956
import java.io.File
6057
import java.io.FileOutputStream
6158
import java.io.IOException
6259
import java.io.OutputStream
6360

6461

65-
6662
class NekoLand : AppCompatActivity(), PrefState.PrefsListener {
6763
private var mPrefs: PrefState? = null
6864
private var mAdapter: CatAdapter? = null
6965
private var mPendingShareCat: Cat? = null
7066
private var numCats = 0
71-
72-
7367
override fun onCreate(savedInstanceState: Bundle?) {
7468
super.onCreate(savedInstanceState)
7569
setContentView(R.layout.neko_activity)
7670
mPrefs = PrefState(this)
71+
7772
if(!mPrefs!!.isConfigured()) {
7873
mPrefs!!.setConf(true)
7974
setupNotificationChannels(this)
@@ -90,7 +85,7 @@ class NekoLand : AppCompatActivity(), PrefState.PrefsListener {
9085
supportActionBar!!.setDisplayShowHomeEnabled(true)
9186
}
9287
window.statusBarColor = ContextCompat.getColor(this, R.color.actionBar)
93-
mPrefs!!.setListener(this)
88+
mPrefs?.setListener(this)
9489
val recyclerView: RecyclerView = findViewById(R.id.holder)
9590
val view = findViewById<LinearLayout>(R.id.frame)
9691
mAdapter = CatAdapter()
@@ -102,8 +97,17 @@ class NekoLand : AppCompatActivity(), PrefState.PrefsListener {
10297

10398
override fun onStart() {
10499
super.onStart()
105-
if(!areNotificationsEnabled(NotificationManagerCompat.from(this))) {
106-
notificationsDialog()
100+
try {
101+
if (!areNotificationsEnabled(NotificationManagerCompat.from(this))) {
102+
notificationsDialog()
103+
}
104+
} catch (e: Exception) {
105+
MaterialAlertDialogBuilder(this)
106+
.setCancelable(false)
107+
.setTitle("error")
108+
.setMessage(e.toString())
109+
.setNegativeButton(android.R.string.cancel, null)
110+
.show()
107111
}
108112
}
109113
private fun areNotificationsEnabled(noman: NotificationManagerCompat) = when {
@@ -161,35 +165,27 @@ class NekoLand : AppCompatActivity(), PrefState.PrefsListener {
161165
}
162166

163167
private fun updateCats(): Int {
164-
val catsUpdate: Deferred<Int> = CoroutineScope(Dispatchers.IO).async {
165-
val cats: Array<Cat?>
166-
if (CAT_GEN) {
167-
cats = arrayOfNulls(50)
168-
for (i in cats.indices) {
169-
cats[i] = Cat.create(this@NekoLand)
170-
}
171-
} else {
172-
val hsv = FloatArray(3)
173-
val list = mPrefs!!.cats
174-
list.sortedWith { cat, cat2 ->
175-
Color.colorToHSV(cat.bodyColor, hsv)
176-
val bodyH1 = hsv[0]
177-
Color.colorToHSV(cat2.bodyColor, hsv)
178-
val bodyH2 = hsv[0]
179-
bodyH1.compareTo(bodyH2)
180-
}
181-
cats = list.toTypedArray<Cat?>()
168+
val cats: Array<Cat?>
169+
if (CAT_GEN) {
170+
cats = arrayOfNulls(50)
171+
for (i in cats.indices) {
172+
cats[i] = Cat.create(this@NekoLand)
182173
}
183-
mAdapter!!.setCats(cats)
184-
185-
return@async cats.size
186-
}
187-
runBlocking {
188-
numCats = catsUpdate.await()
174+
} else {
175+
val hsv = FloatArray(3)
176+
val list = mPrefs!!.cats
177+
list.sortedWith { cat, cat2 ->
178+
Color.colorToHSV(cat.bodyColor, hsv)
179+
val bodyH1 = hsv[0]
180+
Color.colorToHSV(cat2.bodyColor, hsv)
181+
val bodyH2 = hsv[0]
182+
bodyH1.compareTo(bodyH2)
183+
}
184+
cats = list.toTypedArray<Cat?>()
189185
}
190-
return numCats
186+
mAdapter!!.setCats(cats)
187+
return cats.size
191188
}
192-
193189
private fun onCatClick(cat: Cat?) {
194190
if (CAT_GEN) {
195191
if (cat != null) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<TextView
8+
android:id="@+id/textView"
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:layout_marginTop="16dp"
12+
android:textSize="18sp"
13+
android:text="Во время работы Neko11 произошла критическая ошибка. Приложение небходимо перезагрзить. Вы можете помочь исправить ошибку, отправив диагностические данные разработчикам"
14+
app:layout_constraintEnd_toEndOf="parent"
15+
app:layout_constraintStart_toStartOf="parent"
16+
app:layout_constraintTop_toTopOf="parent" />
17+
18+
<com.google.android.material.button.MaterialButton
19+
android:id="@+id/buttonShow"
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:layout_marginTop="24dp"
23+
android:text="Показать"
24+
app:layout_constraintEnd_toEndOf="parent"
25+
app:layout_constraintHorizontal_bias="0.05"
26+
app:layout_constraintStart_toStartOf="parent"
27+
app:layout_constraintTop_toBottomOf="@+id/textView" />
28+
29+
<com.google.android.material.button.MaterialButton
30+
android:id="@+id/buttonCopy"
31+
android:layout_width="wrap_content"
32+
android:layout_height="wrap_content"
33+
android:layout_marginTop="24dp"
34+
android:layout_marginEnd="16dp"
35+
android:text="Скопировать данные"
36+
app:layout_constraintEnd_toEndOf="parent"
37+
app:layout_constraintTop_toBottomOf="@+id/textView" />
38+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values-ru/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
<string name="about">Подробнее</string>
88
<string name="aboutText">Neko7 - это игра, основанная на пасхалке Android 7. Она была создана для розыгрыша в моём основном проекте - Neko11. Суть игры очень проста. Вам нужно собрать как можно больше котов. Развлекайтесь. \nTelegram: @nekoapp_news \nGithub: github.com/queuejw/neko11</string>
99
<string name="notifications_warning">Для работы приложения требуется разрешение на доступ к уведомлениям.</string>
10+
<string name="copy">Скопировать</string>
1011

1112
</resources>

0 commit comments

Comments
 (0)