Skip to content

Commit e2b4f28

Browse files
committed
Initial commit
0 parents  commit e2b4f28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1177
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle.kts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
}
5+
6+
android {
7+
namespace = "com.launium.mcping"
8+
compileSdk = 33
9+
10+
defaultConfig {
11+
applicationId = "com.launium.mcping"
12+
minSdk = 21
13+
targetSdk = 33
14+
versionCode = 1
15+
versionName = "1.0"
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
}
19+
20+
buildTypes {
21+
release {
22+
isMinifyEnabled = true
23+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
24+
}
25+
}
26+
compileOptions {
27+
sourceCompatibility = JavaVersion.VERSION_1_8
28+
targetCompatibility = JavaVersion.VERSION_1_8
29+
}
30+
kotlinOptions {
31+
jvmTarget = "1.8"
32+
}
33+
buildFeatures {
34+
viewBinding = true
35+
}
36+
}
37+
38+
dependencies {
39+
implementation("androidx.core:core-ktx:1.9.0")
40+
implementation("androidx.appcompat:appcompat:1.6.1")
41+
implementation("com.google.android.material:material:1.8.0")
42+
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
43+
implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.6.1")
44+
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
45+
implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
46+
implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
47+
testImplementation("junit:junit:4.13.2")
48+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
49+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
50+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/src/main/AndroidManifest.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.MCPing"
14+
tools:targetApi="31" >
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true"
18+
android:label="@string/app_name" >
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
7.15 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.launium.mcping
2+
3+
import android.os.Bundle
4+
import com.google.android.material.bottomnavigation.BottomNavigationView
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.navigation.findNavController
7+
import androidx.navigation.ui.AppBarConfiguration
8+
import androidx.navigation.ui.setupActionBarWithNavController
9+
import androidx.navigation.ui.setupWithNavController
10+
import com.launium.mcping.databinding.ActivityMainBinding
11+
12+
class MainActivity : AppCompatActivity() {
13+
14+
private lateinit var binding: ActivityMainBinding
15+
16+
override fun onCreate(savedInstanceState: Bundle?) {
17+
super.onCreate(savedInstanceState)
18+
19+
binding = ActivityMainBinding.inflate(layoutInflater)
20+
setContentView(binding.root)
21+
22+
val navView: BottomNavigationView = binding.navView
23+
24+
val navController = findNavController(R.id.nav_host_fragment_activity_main)
25+
// Passing each menu ID as a set of Ids because each
26+
// menu should be considered as top level destinations.
27+
val appBarConfiguration = AppBarConfiguration(
28+
setOf(
29+
R.id.navigation_home, R.id.navigation_discovery, R.id.navigation_settings
30+
)
31+
)
32+
setupActionBarWithNavController(navController, appBarConfiguration)
33+
navView.setupWithNavController(navController)
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.launium.mcping.server
2+
3+
import android.graphics.drawable.Icon
4+
5+
class MinecraftServer() {
6+
constructor(name: String, address: String) : this() {
7+
this.name = name
8+
this.address = address
9+
}
10+
11+
var name = ""
12+
var address = ""
13+
var icon: Icon? = null
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.launium.mcping.ui.discovery
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import android.widget.TextView
8+
import androidx.fragment.app.Fragment
9+
import androidx.lifecycle.ViewModelProvider
10+
import com.launium.mcping.databinding.FragmentDiscoveryBinding
11+
12+
class DiscoveryFragment : Fragment() {
13+
14+
private var _binding: FragmentDiscoveryBinding? = null
15+
16+
// This property is only valid between onCreateView and
17+
// onDestroyView.
18+
private val binding get() = _binding!!
19+
20+
override fun onCreateView(
21+
inflater: LayoutInflater,
22+
container: ViewGroup?,
23+
savedInstanceState: Bundle?
24+
): View {
25+
val discoveryViewModel =
26+
ViewModelProvider(this).get(DiscoveryViewModel::class.java)
27+
28+
_binding = FragmentDiscoveryBinding.inflate(inflater, container, false)
29+
val root: View = binding.root
30+
31+
val textView: TextView = binding.textDashboard
32+
discoveryViewModel.text.observe(viewLifecycleOwner) {
33+
textView.text = it
34+
}
35+
return root
36+
}
37+
38+
override fun onDestroyView() {
39+
super.onDestroyView()
40+
_binding = null
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.launium.mcping.ui.discovery
2+
3+
import androidx.lifecycle.LiveData
4+
import androidx.lifecycle.MutableLiveData
5+
import androidx.lifecycle.ViewModel
6+
7+
class DiscoveryViewModel : ViewModel() {
8+
9+
private val _text = MutableLiveData<String>().apply {
10+
value = "This is discovery Fragment"
11+
}
12+
val text: LiveData<String> = _text
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package com.launium.mcping.ui.home
2+
3+
import android.graphics.Color
4+
import android.os.Bundle
5+
import android.text.SpannableStringBuilder
6+
import android.view.LayoutInflater
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import android.widget.Button
10+
import android.widget.TextView
11+
import android.widget.Toast
12+
import androidx.fragment.app.Fragment
13+
import androidx.lifecycle.ViewModelProvider
14+
import androidx.lifecycle.viewModelScope
15+
import androidx.recyclerview.widget.LinearLayoutManager
16+
import androidx.recyclerview.widget.RecyclerView
17+
import com.google.android.material.bottomsheet.BottomSheetDialog
18+
import com.google.android.material.color.MaterialColors
19+
import com.google.android.material.resources.MaterialAttributes
20+
import com.launium.mcping.R
21+
import com.launium.mcping.databinding.FragmentHomeBinding
22+
import com.launium.mcping.databinding.ServerItemBinding
23+
import com.launium.mcping.server.MinecraftServer
24+
import java.util.Random
25+
26+
class HomeFragment : Fragment() {
27+
28+
private var _binding: FragmentHomeBinding? = null
29+
30+
// This property is only valid between onCreateView and
31+
// onDestroyView.
32+
private val binding get() = _binding!!
33+
34+
private var adapter = Adapter()
35+
36+
override fun onCreateView(
37+
inflater: LayoutInflater,
38+
container: ViewGroup?,
39+
savedInstanceState: Bundle?
40+
): View {
41+
_binding = FragmentHomeBinding.inflate(inflater, container, false)
42+
43+
// set recycler view
44+
val linearLayoutManager = LinearLayoutManager(requireContext())
45+
linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
46+
binding.container.layoutManager = linearLayoutManager
47+
binding.container.adapter = adapter
48+
49+
return binding.root
50+
}
51+
52+
override fun onDestroyView() {
53+
super.onDestroyView()
54+
_binding = null
55+
}
56+
57+
private class Adapter : RecyclerView.Adapter<ServerView>() {
58+
59+
lateinit var servers: List<MinecraftServer>
60+
61+
init {
62+
servers = listOf(
63+
MinecraftServer("first", "hello"),
64+
MinecraftServer("second", "world"),
65+
MinecraftServer("third", "!"),
66+
MinecraftServer("this", ""),
67+
MinecraftServer("is good!", ""),
68+
)
69+
}
70+
71+
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ServerView {
72+
return ServerView(
73+
ServerItemBinding.inflate(
74+
LayoutInflater.from(parent.context),
75+
parent,
76+
false
77+
),
78+
)
79+
}
80+
81+
override fun getItemCount(): Int {
82+
if (!::servers.isInitialized) {
83+
return 0
84+
}
85+
return servers.size
86+
}
87+
88+
override fun onBindViewHolder(holder: ServerView, position: Int) {
89+
holder.bind(servers[position])
90+
}
91+
92+
}
93+
94+
private class ServerView(val binding: ServerItemBinding) :
95+
RecyclerView.ViewHolder(binding.root) {
96+
97+
lateinit var server: MinecraftServer
98+
99+
fun bind(server: MinecraftServer) {
100+
this.server = server
101+
binding.button.text = server.name
102+
binding.pingText.text
103+
binding.pingText.text = R.string.server_latency_message.toString()
104+
.format(System.currentTimeMillis())
105+
106+
binding.button.setOnClickListener {
107+
ServerSheetDialog(binding.root.context, server).show()
108+
}
109+
}
110+
111+
}
112+
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.launium.mcping.ui.home
2+
3+
import androidx.lifecycle.ViewModel
4+
5+
class HomeViewModel : ViewModel() {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.launium.mcping.ui.home
2+
3+
import android.content.Context
4+
import android.text.Editable
5+
import android.widget.Button
6+
import android.widget.TextView
7+
import android.widget.Toast
8+
import com.google.android.material.bottomsheet.BottomSheetDialog
9+
import com.google.android.material.textfield.TextInputEditText
10+
import com.launium.mcping.R
11+
import com.launium.mcping.server.MinecraftServer
12+
13+
class ServerSheetDialog(context: Context, private val server: MinecraftServer) :
14+
BottomSheetDialog(context) {
15+
16+
init {
17+
setContentView(R.layout.server_sheet)
18+
}
19+
20+
override fun onStart() {
21+
super.onStart()
22+
23+
findViewById<TextView>(R.id.server_sheet_name).let {
24+
it?.text = server.name
25+
}
26+
findViewById<TextInputEditText>(R.id.server_sheet_address).let {
27+
it?.text = Editable.Factory.getInstance().newEditable(server.address)
28+
}
29+
findViewById<Button>(R.id.server_sheet_copy_icon).let {
30+
it?.setOnClickListener {
31+
Toast.makeText(context, "Copied!", Toast.LENGTH_SHORT)
32+
.show()
33+
}
34+
}
35+
}
36+
37+
}

0 commit comments

Comments
 (0)