Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
Fix issues: #12, #16
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeShkurko committed Mar 14, 2019
1 parent 3afec4c commit 93b243d
Show file tree
Hide file tree
Showing 11 changed files with 540 additions and 342 deletions.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: SergeShkurko

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: SergeShkurko

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
749 changes: 435 additions & 314 deletions .idea/workspace.xml

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ android {
applicationId "io.scer.pocketmine"
minSdkVersion 19
targetSdkVersion 28
versionCode 191
versionName "2.0.0-beta2"
versionCode 192
versionName "2.0.0-beta3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'arm64-v8a'
}
}
buildTypes {
release {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/io/scer/pocketmine/ServerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import android.content.Intent
import androidx.core.app.NotificationCompat
import io.scer.pocketmine.screens.MainActivity
import io.scer.pocketmine.server.Server
import io.scer.pocketmine.server.ServerBus
import io.scer.pocketmine.server.StopEvent

class ServerService : IntentService("pocketmine_intent_service") {
private val notificationId = 1
Expand All @@ -33,6 +35,10 @@ class ServerService : IntentService("pocketmine_intent_service") {
)
}

private val stopObserver = ServerBus.listen(StopEvent::class.java).subscribe {
stopSelf()
}

override fun onCreate() {
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setOngoing(true)
Expand All @@ -54,6 +60,7 @@ class ServerService : IntentService("pocketmine_intent_service") {
}

override fun onDestroy() {
stopObserver.dispose()
Server.getInstance().kill()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ import io.reactivex.disposables.Disposable
import io.scer.pocketmine.R
import io.scer.pocketmine.server.Server
import io.scer.pocketmine.server.ServerBus
import io.scer.pocketmine.server.StopEvent
import java.util.*
import kotlin.concurrent.schedule

class ConsoleFragment : Fragment() {
private lateinit var editCommand: EditText
private lateinit var labelLog: TextView
private lateinit var scroll: ScrollView
private lateinit var commandRoot: View
private lateinit var serverDisabled: View

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_console, container, false)
Expand All @@ -28,8 +31,8 @@ class ConsoleFragment : Fragment() {
labelLog = view.findViewById(R.id.labelLog)
val send: ImageButton = view.findViewById(R.id.send)
editCommand = view.findViewById(R.id.editCommand)
val commandRoot = view.findViewById<View>(R.id.command_root)
val serverDisabled = view.findViewById<View>(R.id.server_disabled)
commandRoot = view.findViewById<View>(R.id.command_root)
serverDisabled = view.findViewById<View>(R.id.server_disabled)

send.setOnClickListener {
sendCommand()
Expand All @@ -43,10 +46,7 @@ class ConsoleFragment : Fragment() {
false
})

if (!Server.getInstance().isRunning) {
commandRoot.visibility = View.GONE
serverDisabled.visibility = View.VISIBLE
}
if (Server.getInstance().isRunning) toggleCommandLine(true)

messageObserver = ServerBus.Log.listen.subscribe{
if (activity == null) return@subscribe
Expand All @@ -66,8 +66,22 @@ class ConsoleFragment : Fragment() {
return view
}

private fun toggleCommandLine(enable: Boolean) {
commandRoot.visibility = if (enable) View.VISIBLE else View.GONE
serverDisabled.visibility = if (enable) View.GONE else View.VISIBLE
}

private val stopObserver = ServerBus.listen(StopEvent::class.java).subscribe {
if (activity == null) return@subscribe

activity!!.runOnUiThread {
toggleCommandLine(false)
}
}

override fun onDestroyView() {
messageObserver.dispose()
stopObserver.dispose()
super.onDestroyView()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class ServerFragment : Fragment() {

activity!!.runOnUiThread {
toggleButtons(true)
Snackbar.make(view!!, R.string.server_started, Snackbar.LENGTH_LONG).show()
}
}

Expand All @@ -73,7 +72,6 @@ class ServerFragment : Fragment() {

activity!!.runOnUiThread {
toggleButtons(false)
Snackbar.make(view!!, R.string.server_stopped, Snackbar.LENGTH_LONG).show()
}
if (service != null) requireActivity().stopService(service)
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_console.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
card_view:cardElevation="8dp">

<TextView
android:visibility="gone"
android:id="@+id/server_disabled"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -51,7 +50,8 @@
android:orientation="horizontal"
android:background="@color/colorPrimary"
android:gravity="center"
android:layout_gravity="center">
android:layout_gravity="center"
android:visibility="gone">

<EditText
android:id="@+id/editCommand"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
33 changes: 18 additions & 15 deletions server/src/main/java/io/scer/pocketmine/server/utils/StringHtml.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ fun splitKeepDelimiter(string: String, regex: Regex): MutableList<String> {
}

fun String.toHTML(): String {

val csi = "\u001B["
val color = "${csi}38;5;"

print(this)

var tokens = 0
val builder = StringBuilder()
splitKeepDelimiter(this, Regex("\\u001B\\[[\\dm;]+")).forEach { token ->
splitKeepDelimiter(this, Regex("\\u001B\\[[;\\d]*m")).forEach { token ->
when (token) {
"${csi}1m" -> {
builder.append("<span style=\"font-weight:bold;\">")
Expand All @@ -48,67 +51,67 @@ fun String.toHTML(): String {
}

"${color}16m" -> {
builder.append("<span style=\"color:#000;\">")
builder.append("<span style=\"color:#000000;\">")
++tokens
}
"${color}19m" -> {
builder.append("<span style=\"color:#00A;\">")
builder.append("<span style=\"color:#00a00a;\">")
++tokens
}
"${color}34m" -> {
builder.append("<span style=\"color:#0A0\">")
builder.append("<span style=\"color:#0a00a0\">")
++tokens
}
"${color}37m" -> {
builder.append("<span style=\"color:#0AA;\">")
builder.append("<span style=\"color:#0aa0aa;\">")
++tokens
}
"${color}124m" -> {
builder.append("<span style=\"color:#A00;\">")
builder.append("<span style=\"color:#a00a00;\">")
++tokens
}
"${color}127m" -> {
builder.append("<span style=\"color:#A0A;\">")
builder.append("<span style=\"color:#a0aa0a;\">")
++tokens
}
"${color}214m" -> {
builder.append("<span style=\"color:#FA0;\">")
builder.append("<span style=\"color:#fa0fa0;\">")
++tokens
}
"${color}145m" -> {
builder.append("<span style=\"color:#AAA;\">")
builder.append("<span style=\"color:#aaaaaa;\">")
++tokens
}
"${color}59m" -> {
builder.append("<span style=\"color:#555;\">")
builder.append("<span style=\"color:#555555;\">")
++tokens
}
"${color}63m" -> {
builder.append("<span style=\"color:#55F;\">")
builder.append("<span style=\"color:#55f55f;\">")
++tokens
}
"${color}83m" -> {
builder.append("<span style=\"color:#5F5;\">")
builder.append("<span style=\"color:#55ff55;\">")
++tokens
}
"${color}87m" -> {
builder.append("<span style=\"color:blue;\">")
++tokens
}
"${color}203m" -> {
builder.append("<span style=\"color:#F55;\">")
builder.append("<span style=\"color:blue;\">")
++tokens
}
"${color}207m" -> {
builder.append("<span style=\"color:#F5F;\">")
builder.append("<span style=\"color:#f5ff5f;\">")
++tokens
}
"${color}227m" -> {
builder.append("<span style=\"color:#F57F17;\">")
++tokens
}
"${color}231m" -> {
builder.append("<span style=\"color:#000;\">")
builder.append("<span style=\"color:#000000;\">")
++tokens
}
else -> builder.append(token)
Expand Down

0 comments on commit 93b243d

Please sign in to comment.