Skip to content

Commit de9adf3

Browse files
Copilotpsiddh
andauthored
Disable Load Model button until settings change (#132)
* Initial plan * Disable Load Model button until settings change in SettingsActivity - Added fields to track initial values of Backend, Model, Tokenizer, Data Path, and Model Type - Set Load Model button to disabled by default - Added storeInitialSettings() to capture initial values on activity load - Added hasSettingsChanged() to detect if any settings field changed - Added updateLoadModelButtonState() to update button state based on changes - Updated all selector dialogs (Backend, Model, Tokenizer, Data Path, Model Type) to call updateLoadModelButtonState() - Button now only enables when user changes any of the tracked settings Co-authored-by: psiddh <2467117+psiddh@users.noreply.github.com> * Fix null pointer issue in hasSettingsChanged method - Handle null values properly when comparing current and initial settings - Convert null values to empty strings before comparison to avoid NullPointerException Co-authored-by: psiddh <2467117+psiddh@users.noreply.github.com> * Use Objects.equals for enum comparison to handle nulls safely - Replace reference equality (!=) with Objects.equals() for enum comparisons - This handles null values properly and ensures correct equality checking - Addresses code review feedback Co-authored-by: psiddh <2467117+psiddh@users.noreply.github.com> * Complete implementation - all checks passed - Code review completed and addressed - Security scan completed with no alerts - Implementation is ready for testing Co-authored-by: psiddh <2467117+psiddh@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: psiddh <2467117+psiddh@users.noreply.github.com>
1 parent edef966 commit de9adf3

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

Binary file not shown.

llm/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/SettingsActivity.java

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public class SettingsActivity extends AppCompatActivity {
5050
private ModelType mModelType;
5151
public SettingsFields mSettingsFields;
5252

53+
// Store initial values to detect changes
54+
private String mInitialModelFilePath = "";
55+
private String mInitialTokenizerFilePath = "";
56+
private String mInitialDataPath = "";
57+
private BackendType mInitialBackendType;
58+
private ModelType mInitialModelType;
59+
5360
private DemoSharedPreferences mDemoSharedPreferences;
5461
public static double TEMPERATURE_MIN_VALUE = 0.0;
5562

@@ -162,6 +169,9 @@ private void setupSettings() {
162169
setBackendSettingMode();
163170
}
164171

172+
// Store initial values for change detection
173+
storeInitialSettings();
174+
165175
setupParameterSettings();
166176
setupPromptSettings();
167177
setupClearChatHistoryButton();
@@ -170,7 +180,8 @@ private void setupSettings() {
170180

171181
private void setupLoadModelButton() {
172182
mLoadModelButton = requireViewById(R.id.loadModelButton);
173-
mLoadModelButton.setEnabled(true);
183+
// Disable by default until settings change
184+
mLoadModelButton.setEnabled(false);
174185
mLoadModelButton.setOnClickListener(
175186
view -> {
176187
new AlertDialog.Builder(this)
@@ -361,6 +372,7 @@ private void setupBackendSelectorDialog() {
361372
mBackendTextView.setText(backendTypes[item]);
362373
mBackendType = BackendType.valueOf(backendTypes[item]);
363374
setBackendSettingMode();
375+
updateLoadModelButtonState();
364376
dialog.dismiss();
365377
});
366378

@@ -378,7 +390,7 @@ private void setupModelSelectorDialog() {
378390
(dialog, item) -> {
379391
mModelFilePath = pteFiles[item];
380392
mModelTextView.setText(getFilenameFromPath(mModelFilePath));
381-
mLoadModelButton.setEnabled(true);
393+
updateLoadModelButtonState();
382394
dialog.dismiss();
383395
});
384396

@@ -406,7 +418,7 @@ private void setupDataPathSelectorDialog() {
406418
mDataPath = null;
407419
mDataPathTextView.setText(getFilenameFromPath("no data path selected"));
408420
}
409-
mLoadModelButton.setEnabled(true);
421+
updateLoadModelButtonState();
410422
dialog.dismiss();
411423
});
412424

@@ -449,6 +461,7 @@ private void setupModelTypeSelectorDialog() {
449461
mModelTypeTextView.setText(modelTypes[item]);
450462
mModelType = ModelType.valueOf(modelTypes[item]);
451463
mUserPromptEditText.setText(PromptFormat.getUserPromptTemplate(mModelType));
464+
updateLoadModelButtonState();
452465
dialog.dismiss();
453466
});
454467

@@ -466,7 +479,7 @@ private void setupTokenizerSelectorDialog() {
466479
(dialog, item) -> {
467480
mTokenizerFilePath = tokenizerFiles[item];
468481
mTokenizerTextView.setText(getFilenameFromPath(mTokenizerFilePath));
469-
mLoadModelButton.setEnabled(true);
482+
updateLoadModelButtonState();
470483
dialog.dismiss();
471484
});
472485

@@ -484,6 +497,32 @@ private String getFilenameFromPath(String uriFilePath) {
484497
return "";
485498
}
486499

500+
private void storeInitialSettings() {
501+
mInitialModelFilePath = mModelFilePath != null ? mModelFilePath : "";
502+
mInitialTokenizerFilePath = mTokenizerFilePath != null ? mTokenizerFilePath : "";
503+
mInitialDataPath = mDataPath != null ? mDataPath : "";
504+
mInitialBackendType = mBackendType;
505+
mInitialModelType = mModelType;
506+
}
507+
508+
private boolean hasSettingsChanged() {
509+
String currentModelPath = mModelFilePath != null ? mModelFilePath : "";
510+
String currentTokenizerPath = mTokenizerFilePath != null ? mTokenizerFilePath : "";
511+
String currentDataPath = mDataPath != null ? mDataPath : "";
512+
513+
boolean modelChanged = !currentModelPath.equals(mInitialModelFilePath);
514+
boolean tokenizerChanged = !currentTokenizerPath.equals(mInitialTokenizerFilePath);
515+
boolean dataPathChanged = !currentDataPath.equals(mInitialDataPath);
516+
boolean backendChanged = !java.util.Objects.equals(mBackendType, mInitialBackendType);
517+
boolean modelTypeChanged = !java.util.Objects.equals(mModelType, mInitialModelType);
518+
519+
return modelChanged || tokenizerChanged || dataPathChanged || backendChanged || modelTypeChanged;
520+
}
521+
522+
private void updateLoadModelButtonState() {
523+
mLoadModelButton.setEnabled(hasSettingsChanged());
524+
}
525+
487526
private void setBackendSettingMode() {
488527
if (mBackendType.equals(BackendType.XNNPACK) || mBackendType.equals(BackendType.QUALCOMM)) {
489528
setXNNPACKSettingMode();

0 commit comments

Comments
 (0)