Skip to content

Commit c61814c

Browse files
committed
feat: Add files!!!
1 parent ae07293 commit c61814c

File tree

8 files changed

+201
-19
lines changed

8 files changed

+201
-19
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.mokkachocolata.pcsimulatorsaveeditorandroidport
2+
3+
import android.annotation.SuppressLint
4+
import android.os.Bundle
5+
import android.text.InputType
6+
import android.view.LayoutInflater
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import android.widget.Button
10+
import android.widget.EditText
11+
import android.widget.TextView
12+
import androidx.fragment.app.DialogFragment
13+
import org.json.JSONObject
14+
import java.lang.Long.parseLong
15+
16+
class FileFragment(val obj: JSONObject, val textBox: EditText, val objindex : Int, val index: Int) : DialogFragment() {
17+
lateinit var aktivity: MainActivity2
18+
private fun doItEdittext(title: String, message: String, propertyName: String, long: Boolean) {
19+
val edittext = EditText(aktivity)
20+
if (long) {
21+
edittext.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL or InputType.TYPE_NUMBER_FLAG_SIGNED
22+
}
23+
edittext.setText(obj.get(propertyName).toString())
24+
aktivity.dialog(title, message ,{_, _ ->
25+
val text = textBox.text.toString()
26+
val lines = text.lines()
27+
val jsonObject = JSONObject(lines[1])
28+
val itemArray = jsonObject.getJSONArray("itemData")
29+
val itemObject = itemArray.getJSONObject(objindex)
30+
val file = itemObject.getJSONObject("data").getJSONArray("files").getJSONObject(index)
31+
file.put(propertyName, if (long) parseLong(edittext.text.toString()) else edittext.text.toString())
32+
textBox.setText(lines[0] + "\n" + jsonObject.toString())
33+
dismiss()
34+
} , {_, _ ->}, edittext)
35+
}
36+
@SuppressLint("SetTextI18n")
37+
override fun onCreateView(
38+
inflater: LayoutInflater,
39+
container: ViewGroup?,
40+
savedInstanceState: Bundle?
41+
): View? {
42+
super.onCreateView(inflater, container, savedInstanceState)
43+
aktivity = activity as MainActivity2
44+
val text = textBox.text.toString()
45+
val lines = text.lines()
46+
val jsonObject = JSONObject(lines[1])
47+
val itemArray = jsonObject.getJSONArray("itemData")
48+
val file = itemArray.getJSONObject(objindex).getJSONObject("data").getJSONArray("files").getJSONObject(index)
49+
val flate = inflater.inflate(R.layout.fragment_file, container, false)
50+
val size = file.getInt("size")
51+
val hidden = file.getBoolean("hidden")
52+
flate.findViewById<TextView>(R.id.size).text = size.toString()
53+
flate.findViewById<TextView>(R.id.hidden).text = if (hidden) "Hidden" else "Visible"
54+
flate.findViewById<TextView>(R.id.title).text = file.getString("path")
55+
flate.findViewById<Button>(R.id.delete).setOnClickListener {
56+
itemArray.getJSONObject(objindex).getJSONObject("data").getJSONArray("files").remove(index)
57+
textBox.setText(lines[0] + "\n" + jsonObject.toString())
58+
dismiss()
59+
}
60+
flate.findViewById<Button>(R.id.rename).setOnClickListener {
61+
doItEdittext("Rename", "", "spawnId", false)
62+
}
63+
flate.findViewById<Button>(R.id.dupe).setOnClickListener {
64+
val edittext = EditText(aktivity)
65+
edittext.setText(obj.get("path").toString())
66+
aktivity.dialog("Duplicate path", "",{_, _ ->
67+
val clone = JSONObject(file.toString())
68+
clone.put("path", edittext.text)
69+
itemArray.getJSONObject(objindex).getJSONObject("data").getJSONArray("files").put(clone)
70+
textBox.setText(lines[0] + "\n" + jsonObject.toString())
71+
}, {_,_->}, edittext)
72+
}
73+
flate.findViewById<Button>(R.id.makhidden).text = if (file.getBoolean("hidden")) "Make visible" else "Make hidden"
74+
flate.findViewById<Button>(R.id.makhidden).setOnClickListener {
75+
itemArray.getJSONObject(objindex).getJSONObject("data").getJSONArray("files").getJSONObject(index).put("hidden", !itemArray.getJSONObject(objindex).getJSONObject("data").getJSONArray("files").getJSONObject(index).getBoolean("hidden"))
76+
flate.findViewById<Button>(R.id.makhidden).text = if (file.getBoolean("hidden")) "Make visible" else "Make hidden"
77+
textBox.setText(lines[0] + "\n" + jsonObject.toString())
78+
}
79+
return flate
80+
}
81+
82+
}

app/src/main/java/com/mokkachocolata/pcsimulatorsaveeditorandroidport/MainActivity2.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ class MainActivity2 : AppCompatActivity() {
937937
handleClickJson(i)
938938
}
939939
}
940-
R.id.rotation -> {
940+
R.id.hidden -> {
941941
dialog("Open Source Licenses", """
942942
This app is licensed with GPLv3.0 or later.
943943
AndroidX (Apache License 2.0)

app/src/main/java/com/mokkachocolata/pcsimulatorsaveeditorandroidport/ModFragment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class ModFragment(val mod: MainActivity2.Mod) : DialogFragment() {
2525
if (mod.repositoryUrl?.isEmpty() == true) flate.findViewById<TextView>(R.id.repo).visibility = View.GONE
2626
flate.findViewById<TextView>(R.id.creator).text = mod.creator
2727
flate.findViewById<TextView>(R.id.title).text = mod.name
28-
flate.findViewById<TextView>(R.id.pos).text = mod.description
29-
flate.findViewById<TextView>(R.id.rotation).text = mod.license
28+
flate.findViewById<TextView>(R.id.size).text = mod.description
29+
flate.findViewById<TextView>(R.id.hidden).text = mod.license
3030
flate.findViewById<TextView>(R.id.version).text = mod.version
3131
flate.findViewById<Button>(R.id.delete).setOnClickListener { deleteListener() }
3232
return flate

app/src/main/java/com/mokkachocolata/pcsimulatorsaveeditorandroidport/ObjectFragment.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ObjectFragment(val obj: JSONObject, val textBox: EditText, val index: Int)
4444
val pos = obj.getJSONObject("pos")
4545
val rot = obj.getJSONObject("rot")
4646
flate.findViewById<TextView>(R.id.pos).text = "${pos.getDouble("x")}, ${pos.getDouble("y")}, ${pos.getDouble("z")}"
47-
flate.findViewById<TextView>(R.id.rotation).text = "${rot.getDouble("x")}, ${rot.getDouble("y")}, ${rot.getDouble("z")}, ${rot.getDouble("w")}"
47+
flate.findViewById<TextView>(R.id.rot).text = "${rot.getDouble("x")}, ${rot.getDouble("y")}, ${rot.getDouble("z")}, ${rot.getDouble("w")}"
4848
flate.findViewById<TextView>(R.id.smasnug).text = "ID: ${obj.getInt("id")}"
4949
flate.findViewById<TextView>(R.id.title).text = obj.getString("spawnId")
5050
flate.findViewById<Button>(R.id.delete).setOnClickListener {
@@ -59,7 +59,7 @@ class ObjectFragment(val obj: JSONObject, val textBox: EditText, val index: Int)
5959
flate.findViewById<Button>(R.id.setSpawnID).setOnClickListener {
6060
doItEdittext("Set spawn ID", "", "spawnId", false)
6161
}
62-
flate.findViewById<Button>(R.id.setID).setOnClickListener {
62+
flate.findViewById<Button>(R.id.setId).setOnClickListener {
6363
doItEdittext("Set ID", "", "id", true)
6464
}
6565
if (!(obj.getString("spawnId").contains("SSD") or obj.getString("spawnId").contains("HDD") or obj.getString("spawnId").contains("SSD_M.2") or obj.getString("spawnId").contains("FlashDrive")))
@@ -69,8 +69,9 @@ class ObjectFragment(val obj: JSONObject, val textBox: EditText, val index: Int)
6969
val data = obj.getJSONObject("data")
7070
for (file in data.getJSONArray("files"))
7171
lists.add(file.getString("path"))
72-
aktivity.dialog("File Explorer", "", null, {_,_->}, null, "Close", lists.toTypedArray()) {_, i ->
73-
72+
aktivity.dialog("File Explorer", null, null, {_,_->}, null, "Close", lists.toTypedArray()) {_, i ->
73+
val fragment = FileFragment(obj, textBox, index, i)
74+
fragment.show(aktivity.supportFragmentManager, "fileFragment")
7475
}
7576
}
7677
return flate
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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/size"
9+
android:layout_width="wrap_content"
10+
android:layout_height="wrap_content"
11+
android:layout_marginTop="32dp"
12+
android:text="10MB"
13+
app:layout_constraintStart_toStartOf="@+id/title"
14+
app:layout_constraintTop_toBottomOf="@+id/title" />
15+
16+
<TextView
17+
android:id="@+id/hidden"
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:layout_marginTop="12dp"
21+
android:text="Hidden"
22+
app:layout_constraintStart_toStartOf="@+id/size"
23+
app:layout_constraintTop_toBottomOf="@+id/size" />
24+
25+
<TextView
26+
android:id="@+id/title"
27+
android:layout_width="wrap_content"
28+
android:layout_height="wrap_content"
29+
android:layout_marginStart="16dp"
30+
android:layout_marginTop="16dp"
31+
android:text="TextView"
32+
android:textStyle="bold"
33+
app:layout_constraintStart_toStartOf="parent"
34+
app:layout_constraintTop_toTopOf="parent" />
35+
36+
<Button
37+
android:id="@+id/delete"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_marginTop="24dp"
41+
android:text="Delete"
42+
app:layout_constraintStart_toStartOf="@+id/hidden"
43+
app:layout_constraintTop_toBottomOf="@+id/hidden" />
44+
45+
<View
46+
android:id="@+id/view2"
47+
android:layout_width="320dp"
48+
android:layout_height="300dp"
49+
app:layout_constraintBottom_toBottomOf="parent"
50+
app:layout_constraintEnd_toEndOf="parent"
51+
app:layout_constraintStart_toStartOf="parent"
52+
app:layout_constraintTop_toTopOf="parent" />
53+
54+
<Button
55+
android:id="@+id/rename"
56+
android:layout_width="wrap_content"
57+
android:layout_height="wrap_content"
58+
android:layout_marginStart="8dp"
59+
android:text="Rename"
60+
app:layout_constraintStart_toEndOf="@+id/delete"
61+
app:layout_constraintTop_toTopOf="@+id/delete" />
62+
63+
<Button
64+
android:id="@+id/edit"
65+
android:layout_width="wrap_content"
66+
android:layout_height="wrap_content"
67+
android:layout_marginStart="12dp"
68+
android:text="Edit"
69+
app:layout_constraintStart_toEndOf="@+id/rename"
70+
app:layout_constraintTop_toTopOf="@+id/rename" />
71+
72+
<Button
73+
android:id="@+id/setSize"
74+
android:layout_width="wrap_content"
75+
android:layout_height="wrap_content"
76+
android:layout_marginTop="12dp"
77+
android:text="Set Size"
78+
app:layout_constraintStart_toStartOf="@+id/delete"
79+
app:layout_constraintTop_toBottomOf="@+id/delete" />
80+
81+
<Button
82+
android:id="@+id/dupe"
83+
android:layout_width="wrap_content"
84+
android:layout_height="wrap_content"
85+
android:layout_marginStart="12dp"
86+
android:text="Duplicate"
87+
app:layout_constraintStart_toEndOf="@+id/setSize"
88+
app:layout_constraintTop_toTopOf="@+id/setSize" />
89+
90+
<Button
91+
android:id="@+id/makhidden"
92+
android:layout_width="wrap_content"
93+
android:layout_height="wrap_content"
94+
android:layout_marginStart="8dp"
95+
android:text="Make hidden"
96+
app:layout_constraintStart_toEndOf="@+id/dupe"
97+
app:layout_constraintTop_toTopOf="@+id/dupe" />
98+
99+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/fragment_object.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
app:layout_constraintTop_toBottomOf="@+id/title" />
1515

1616
<TextView
17-
android:id="@+id/rotation"
17+
android:id="@+id/rot"
1818
android:layout_width="wrap_content"
1919
android:layout_height="wrap_content"
2020
android:layout_marginTop="12dp"
@@ -48,8 +48,8 @@
4848
android:layout_height="wrap_content"
4949
android:layout_marginTop="24dp"
5050
android:text="Delete"
51-
app:layout_constraintStart_toStartOf="@+id/rotation"
52-
app:layout_constraintTop_toBottomOf="@+id/rotation" />
51+
app:layout_constraintStart_toStartOf="@+id/rot"
52+
app:layout_constraintTop_toBottomOf="@+id/rot" />
5353

5454
<View
5555
android:id="@+id/view2"
@@ -88,7 +88,7 @@
8888
app:layout_constraintTop_toBottomOf="@+id/delete" />
8989

9090
<Button
91-
android:id="@+id/setID"
91+
android:id="@+id/setId"
9292
android:layout_width="wrap_content"
9393
android:layout_height="wrap_content"
9494
android:layout_marginStart="12dp"
@@ -102,6 +102,6 @@
102102
android:layout_height="wrap_content"
103103
android:layout_marginStart="8dp"
104104
android:text="File Browser"
105-
app:layout_constraintStart_toEndOf="@+id/setID"
106-
app:layout_constraintTop_toTopOf="@+id/setID" />
105+
app:layout_constraintStart_toEndOf="@+id/setId"
106+
app:layout_constraintTop_toTopOf="@+id/setId" />
107107
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/mod_fragment.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
android:layout_height="match_parent">
66

77
<TextView
8-
android:id="@+id/pos"
8+
android:id="@+id/size"
99
android:layout_width="wrap_content"
1010
android:layout_height="wrap_content"
1111
android:layout_marginTop="32dp"
@@ -14,13 +14,13 @@
1414
app:layout_constraintTop_toBottomOf="@+id/title" />
1515

1616
<TextView
17-
android:id="@+id/rotation"
17+
android:id="@+id/hidden"
1818
android:layout_width="wrap_content"
1919
android:layout_height="wrap_content"
2020
android:layout_marginTop="12dp"
2121
android:text="License"
22-
app:layout_constraintStart_toStartOf="@+id/pos"
23-
app:layout_constraintTop_toBottomOf="@+id/pos" />
22+
app:layout_constraintStart_toStartOf="@+id/size"
23+
app:layout_constraintTop_toBottomOf="@+id/size" />
2424

2525
<TextView
2626
android:id="@+id/repo"
@@ -31,7 +31,7 @@
3131
android:text="Visit the repository"
3232
android:textColor="#0027FF"
3333
app:layout_constraintEnd_toEndOf="parent"
34-
app:layout_constraintTop_toBottomOf="@+id/rotation" />
34+
app:layout_constraintTop_toBottomOf="@+id/hidden" />
3535

3636
<TextView
3737
android:id="@+id/creator"

app/src/main/res/menu/menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
android:title="Keyboard Shortcuts"
4848
android:titleCondensed="Shortcuts" />
4949
<item
50-
android:id="@+id/rotation"
50+
android:id="@+id/hidden"
5151
android:title="Open Source Licenses"
5252
android:titleCondensed="Licenses" />
5353
<item

0 commit comments

Comments
 (0)