-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from MrApplejuice/debug-menu-item
Add debug allowing to debug server <-> client communication in production builds
- Loading branch information
Showing
9 changed files
with
177 additions
and
21 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
49 changes: 49 additions & 0 deletions
49
app/src/main/java/eu/pkgsoftware/babybuddywidgets/debugging/DebugLogDisplay.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,49 @@ | ||
package eu.pkgsoftware.babybuddywidgets.debugging | ||
|
||
import android.content.ClipData | ||
import android.content.ClipboardManager | ||
import android.content.Context | ||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.Toast | ||
import eu.pkgsoftware.babybuddywidgets.BaseFragment | ||
import eu.pkgsoftware.babybuddywidgets.R | ||
import eu.pkgsoftware.babybuddywidgets.databinding.FragmentDebugLogDisplayBinding | ||
|
||
class DebugLogDisplay : BaseFragment() { | ||
lateinit var fragment: FragmentDebugLogDisplayBinding | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
|
||
val stringBuilder = StringBuilder(16000) | ||
for (line in GlobalDebugObject.getLog()) { | ||
stringBuilder.append(line.trim()) | ||
stringBuilder.append("\n<EOL>\n") | ||
} | ||
fragment.debugTextArea.setText(stringBuilder) | ||
|
||
mainActivity.setTitle(getString(R.string.export_debug_logs_title)) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
fragment = FragmentDebugLogDisplayBinding.inflate(inflater) | ||
|
||
fragment.copyToClipboardButton.setOnClickListener { | ||
val clipboard = requireActivity().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager | ||
clipboard.setPrimaryClip(ClipData.newPlainText( | ||
"BabyBuddy Debug Data", fragment.debugTextArea.text | ||
)) | ||
|
||
Toast.makeText(context, "Copied to clipboard", Toast.LENGTH_SHORT).show() | ||
} | ||
|
||
return fragment.root | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/eu/pkgsoftware/babybuddywidgets/debugging/GlobalDebugObject.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,41 @@ | ||
package eu.pkgsoftware.babybuddywidgets.debugging | ||
|
||
import android.util.Log | ||
|
||
class GlobalDebugObject { | ||
companion object { | ||
@JvmStatic | ||
val ENABLED = true | ||
@JvmStatic | ||
val DO_PRINT = true | ||
@JvmStatic | ||
val LOG_FILE_MESSAGE_LIMIT = 10000 | ||
|
||
val LOCK = Object() | ||
|
||
private val log = mutableListOf<String>() | ||
|
||
@JvmStatic | ||
fun log(msg: String) { | ||
if (!ENABLED) return | ||
synchronized(LOCK) { | ||
while (log.size > LOG_FILE_MESSAGE_LIMIT) { | ||
log.removeAt(0) | ||
} | ||
if (DO_PRINT) { | ||
Log.println(Log.DEBUG, "GlobalDebugObject.log", msg) | ||
} | ||
log.add(msg) | ||
} | ||
} | ||
|
||
@JvmStatic | ||
fun getLog(): List<String> { | ||
if (!ENABLED) return listOf() | ||
val result = synchronized(LOCK) { | ||
log.toList() | ||
} | ||
return result | ||
} | ||
} | ||
} |
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,44 @@ | ||
<?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" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".debugging.DebugLogDisplay"> | ||
|
||
<ScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="0dp" | ||
android:layout_marginBottom="8dp" | ||
app:layout_constraintBottom_toTopOf="@+id/copyToClipboardButton" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="1.0" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent"> | ||
|
||
<EditText | ||
android:id="@+id/debugTextArea" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:ems="10" | ||
android:enabled="false" | ||
android:fontFamily="monospace" | ||
android:gravity="start|top" | ||
android:inputType="textMultiLine" | ||
android:textAlignment="viewStart" | ||
android:textColor="#000000" | ||
android:textIsSelectable="true" | ||
android:textSize="12sp" /> | ||
</ScrollView> | ||
|
||
<Button | ||
android:id="@+id/copyToClipboardButton" | ||
android:layout_width="match_parent" | ||
android:layout_height="54dp" | ||
android:layout_marginEnd="16dp" | ||
android:layout_marginStart="16dp" | ||
android:text="@string/export_debug_logs_menu_item_copy_to_clipboard" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" /> | ||
</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
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