Skip to content

Commit cfab304

Browse files
Add files via upload (#14)
1 parent acbed3c commit cfab304

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

app/src/main/kotlin/com/google/ai/sample/util/SystemMessagePreferences.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ object SystemMessagePreferences {
1111
private const val TAG = "SystemMessagePrefs"
1212
private const val PREFS_NAME = "system_message_prefs"
1313
private const val KEY_SYSTEM_MESSAGE = "system_message"
14+
private const val KEY_FIRST_START_COMPLETED = "first_start_completed" // New flag
15+
16+
// Content from pasted_content.txt
17+
private const val DEFAULT_SYSTEM_MESSAGE_ON_FIRST_START = """You are on an App on a Smartphone. You're app is called Generative AI Sample App. You start from this app. Proceed step by step! DON'T USE TOOL CODE! You must operate the screen with exactly following commands: "`home()`" "`back()`" "`recentApps()`" for buttons and words: "`clickOnButton("sample")`" "`tapAtCoordinates(x, y)`" "`scrollDown()`" "`scrollUp()`" "`scrollLeft()`" "`scrollRight()`" "`scrollDown(x, y, how much pixel to scroll, duration in milliseconds)`" "`scrollUp(x, y, how much pixel to scroll, duration in milliseconds)`" "`scrollLeft(x, y, how much pixel to scroll, duration in milliseconds)`" "`scrollRight(x, y, how much pixel to scroll, duration in milliseconds)`" scroll status bar down: "`scrollUp(540, 0, 1100, 50)`" Only the Play Store and Settings can be opened this way: "`openApps("sample")`" You must open other apps from the home screen. "`takeScreenshot()`" To write text, search and click the textfield thereafter: "`writeText("sample text")`" You need to write the already existing text, if it should continue exist. If the keyboard is displayed, you can press "`Enter()`". Otherwise, you have to open the keyboard by clicking on the text field. In Termux you have to swipe the bar to the left and "`Enter()`" twice. You can see the screen and get additional Informations about them with: "`takeScreenshot()`" You need this command at the and of every message until you are finish. When you're done don't say "`takeScreenshot()`" Your task is:"""
1418

1519
/**
1620
* Save system message to SharedPreferences
@@ -28,17 +32,32 @@ object SystemMessagePreferences {
2832
}
2933

3034
/**
31-
* Load system message from SharedPreferences
35+
* Load system message from SharedPreferences.
36+
* On first start, it loads a default message, saves it, and marks first start as completed.
3237
*/
3338
fun loadSystemMessage(context: Context): String {
3439
try {
3540
val sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
36-
val message = sharedPreferences.getString(KEY_SYSTEM_MESSAGE, "") ?: ""
37-
Log.d(TAG, "Loaded system message: $message")
38-
return message
41+
val isFirstStartCompleted = sharedPreferences.getBoolean(KEY_FIRST_START_COMPLETED, false)
42+
43+
if (!isFirstStartCompleted) {
44+
Log.d(TAG, "First start detected. Loading and saving default system message.")
45+
// Save the default message and the flag
46+
val editor = sharedPreferences.edit()
47+
editor.putString(KEY_SYSTEM_MESSAGE, DEFAULT_SYSTEM_MESSAGE_ON_FIRST_START)
48+
editor.putBoolean(KEY_FIRST_START_COMPLETED, true)
49+
editor.apply()
50+
Log.d(TAG, "Loaded default system message: $DEFAULT_SYSTEM_MESSAGE_ON_FIRST_START")
51+
return DEFAULT_SYSTEM_MESSAGE_ON_FIRST_START
52+
} else {
53+
val message = sharedPreferences.getString(KEY_SYSTEM_MESSAGE, "") ?: ""
54+
Log.d(TAG, "Loaded system message from prefs: $message")
55+
return message
56+
}
3957
} catch (e: Exception) {
4058
Log.e(TAG, "Error loading system message: ${e.message}", e)
41-
return ""
59+
return "" // Return empty string in case of error, consistent with original behavior
4260
}
4361
}
4462
}
63+

0 commit comments

Comments
 (0)