Skip to content

Commit 2d647be

Browse files
authored
Migrate from Java to Kotlin (#24)
1 parent 2e292c5 commit 2d647be

16 files changed

+505
-671
lines changed

f3d/src/main/java/app/f3d/F3D/android/Line.java

Lines changed: 0 additions & 113 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app.f3d.F3D.android
2+
3+
/**
4+
* Provides a simple implementation of a line with two points.
5+
*/
6+
class Line(firstPoint: Point = Point(), secondPoint: Point = Point()) {
7+
var p1: Point = firstPoint
8+
var p2: Point = secondPoint
9+
10+
val center: Point
11+
/**
12+
* Calculates the center point of the line.
13+
* @return A point representing the center of the line.
14+
*/
15+
get() = Point((this.p1.x + this.p2.x) / 2, (this.p1.y + this.p2.y) / 2)
16+
}

f3d/src/main/java/app/f3d/F3D/android/MainActivity.java

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package app.f3d.F3D.android
2+
3+
import android.net.Uri
4+
import android.os.Bundle
5+
import android.view.View
6+
import androidx.activity.result.ActivityResultCallback
7+
import androidx.activity.result.ActivityResultLauncher
8+
import androidx.appcompat.app.ActionBar
9+
import androidx.appcompat.app.AppCompatActivity
10+
import androidx.constraintlayout.widget.ConstraintLayout
11+
import app.f3d.F3D.android.Utils.FileInteractionContract
12+
import com.google.android.material.floatingactionbutton.FloatingActionButton
13+
import java.util.Objects
14+
15+
class MainActivity : AppCompatActivity() {
16+
private var mView: MainView? = null
17+
private var fileInteractionLauncher: ActivityResultLauncher<Void?>? = null
18+
19+
override fun onCreate(savedInstanceState: Bundle?) {
20+
super.onCreate(savedInstanceState)
21+
setContentView(R.layout.activity_main)
22+
23+
val mainLayout = findViewById<ConstraintLayout>(R.id.mainLayout)
24+
25+
val addButton = findViewById<FloatingActionButton>(R.id.addButton)
26+
27+
supportActionBar!!.hide()
28+
29+
mView = MainView(this)
30+
31+
handleSelectedFileAppNotOpen()
32+
33+
fileInteractionLauncher = registerForActivityResult<Void?, Uri?>(
34+
FileInteractionContract(),
35+
ActivityResultCallback { uri: Uri? -> this.handleSelectedFile(uri) })
36+
37+
addButton.setOnClickListener(View.OnClickListener { view: View? ->
38+
fileInteractionLauncher!!.launch(null)
39+
})
40+
41+
mainLayout.addView(mView)
42+
}
43+
44+
private fun handleSelectedFile(uri: Uri?) {
45+
mView!!.updateActiveUri(uri)
46+
}
47+
48+
private fun handleSelectedFileAppNotOpen() {
49+
val intent = getIntent()
50+
if (intent != null && intent.data != null) {
51+
val uri = intent.data
52+
handleSelectedFile(uri)
53+
}
54+
}
55+
56+
override fun onPause() {
57+
super.onPause()
58+
mView!!.onPause()
59+
}
60+
61+
override fun onResume() {
62+
super.onResume()
63+
mView!!.onResume()
64+
}
65+
}

0 commit comments

Comments
 (0)