-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: roshan <[email protected]> Co-authored-by: dogi <[email protected]>
- Loading branch information
1 parent
554212e
commit 434b536
Showing
13 changed files
with
226 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ gen/ | |
/build | ||
/captures | ||
.externalNativeBuild | ||
app/src/main/assets/bluetooth-server.txt | ||
.vagrant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/build | ||
/src/main/assets/bluetooth-server.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/src/main/kotlin/io/treehouses/remote/Fragments/ShowBluetoothFile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package io.treehouses.remote.Fragments | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.lifecycleScope | ||
import io.github.kbiakov.codeview.CodeView | ||
import io.github.kbiakov.codeview.adapters.Options | ||
import io.github.kbiakov.codeview.highlight.ColorTheme | ||
import io.treehouses.remote.databinding.CodeViewBinding | ||
import io.treehouses.remote.databinding.FragmentShowBluetoothFileBinding | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
|
||
class ShowBluetoothFile : Fragment() { | ||
private lateinit var bind : FragmentShowBluetoothFileBinding | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
bind = FragmentShowBluetoothFileBinding.inflate(inflater, container, false) | ||
return bind.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
bind.pbar.visibility = View.VISIBLE | ||
lifecycleScope.launch(Dispatchers.IO) { | ||
val code = context?.assets?.open("bluetooth-server.txt")?.bufferedReader().use { it?.readText() } | ||
Log.e("GOT CODE", code) | ||
withContext(Dispatchers.Main) { | ||
if (code == null) { | ||
bind.fileNotFound.visibility = View.VISIBLE | ||
} else { | ||
withContext(Dispatchers.Default) { | ||
val codeView = createCodeView(code) | ||
withContext(Dispatchers.Main) { | ||
bind.scriptContainer.addView(codeView, ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)) | ||
bind.pbar.visibility = View.GONE | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun createCodeView(code : String) : CodeView { | ||
val codeView = CodeViewBinding.inflate(layoutInflater).root | ||
codeView.setOptions(Options.Default.get(requireContext()) | ||
.withLanguage("python") | ||
.withCode(code) | ||
.withTheme(ColorTheme.MONOKAI)) | ||
return codeView | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<io.github.kbiakov.codeview.CodeView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/codeView" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</io.github.kbiakov.codeview.CodeView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<TextView | ||
android:id="@+id/title" | ||
style="@style/TextAppearance.AppCompat.Title" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:padding="@dimen/padding_large" | ||
android:text="bluetooth-server.py" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
<FrameLayout | ||
android:id="@+id/scriptContainer" | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@id/title"/> | ||
|
||
<ProgressBar | ||
android:id="@+id/pbar" | ||
android:visibility="gone" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/title" /> | ||
|
||
<LinearLayout | ||
android:id="@+id/fileNotFound" | ||
android:visibility="gone" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:orientation="vertical" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"> | ||
|
||
<ImageView | ||
android:layout_width="50dp" | ||
android:layout_height="50dp" | ||
android:background="@drawable/ic_update_alert" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="File Not Found!" /> | ||
</LinearLayout> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters