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

Commit

Permalink
Optimizations & refactoring
Browse files Browse the repository at this point in the history
Small additions (Stop server button in notification)
Show notification on Android Oreo
Rewrite source code app from Java to Kotlin
  • Loading branch information
SergeShkurko committed Aug 15, 2018
1 parent 62e7800 commit e7fd760
Show file tree
Hide file tree
Showing 27 changed files with 1,152 additions and 742 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 1 addition & 0 deletions .idea/dictionaries/Serge.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

11 changes: 11 additions & 0 deletions .idea/libraries/Gradle__org_jetbrains_annotations_13_0_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

720 changes: 524 additions & 196 deletions .idea/workspace.xml

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'


android {
compileSdkVersion 27
defaultConfig {
applicationId "io.scer.pocketmine"
minSdkVersion 15
targetSdkVersion 27
versionCode 4
versionName "1.0.1"
versionCode 6
versionName "1.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -21,8 +24,12 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
repositories {
mavenCentral()
}
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@


<application
android:allowBackup="true"
android:name=".App"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
Expand All @@ -24,7 +25,8 @@
<service
android:name="io.scer.pocketmine.ServerService"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" />
android:label="@string/app_name"
android:exported="false"/>

<activity
android:name="io.scer.pocketmine.ConsoleActivity"
Expand Down
32 changes: 32 additions & 0 deletions app/src/main/java/io/scer/pocketmine/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.scer.pocketmine

import android.app.NotificationManager
import android.app.NotificationChannel
import android.os.Build
import android.app.Application
import android.support.annotation.RequiresApi

const val CHANNEL_ID = "pocketmine_service_channel"

class App : Application() {

override fun onCreate() {
super.onCreate()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createNotificationChannel()
}
}

@RequiresApi(Build.VERSION_CODES.O)
private fun createNotificationChannel() {
val serviceChannel = NotificationChannel(
CHANNEL_ID,
"Pocketmine Service Channel",
NotificationManager.IMPORTANCE_DEFAULT
)

val manager = getSystemService(NotificationManager::class.java)
manager!!.createNotificationChannel(serviceChannel)
}
}
84 changes: 0 additions & 84 deletions app/src/main/java/io/scer/pocketmine/ConsoleActivity.java

This file was deleted.

65 changes: 65 additions & 0 deletions app/src/main/java/io/scer/pocketmine/ConsoleActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.scer.pocketmine

import android.annotation.SuppressLint
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.widget.ScrollView
import io.scer.pocketmine.server.Server
import kotlinx.android.synthetic.main.activity_console.*

class ConsoleActivity : AppCompatActivity(), Handler.Callback {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_console)

instance = this

labelLog.textSize = MainActivity.fontSize.toFloat()

send.setOnClickListener {
Server.getInstance().sendCommand(editCommand.text.toString())
editCommand.setText("")
}

labelLog.text = currentLog
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.console, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.clear -> {
labelLog.text = ""
currentLog = ""
}
}
return super.onOptionsItemSelected(item)
}

override fun handleMessage(message: Message): Boolean {
return false
}

companion object {
@SuppressLint("StaticFieldLeak")
var instance: ConsoleActivity? = null
var currentLog = ""

fun log(text: String) {
currentLog += text
if (instance != null) {
instance!!.runOnUiThread {
instance!!.labelLog.append(text)
instance!!.scroll.fullScroll(ScrollView.FOCUS_DOWN)
}
}
}
}
}
Loading

0 comments on commit e7fd760

Please sign in to comment.