Skip to content

Commit

Permalink
Get models on textfield change
Browse files Browse the repository at this point in the history
  • Loading branch information
DataDropp committed Feb 28, 2024
1 parent aa5b4f5 commit ce6e085
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions app/src/main/java/com/lvnvceo/ollamadroid/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
Expand Down Expand Up @@ -71,34 +73,44 @@ public void onCreate(Bundle savedInstance) {
editor.apply();
finish();
});
ollamaAPIURL.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {
try {
getModels(new URL(ollamaAPIURL.getText().toString()));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
});

modelSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
model = parent.getItemAtPosition(position).toString();
((TextView) parent.getChildAt(0)).setTextColor(getColor(com.google.android.material.R.color.design_default_color_on_primary));
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});
getModels();

}
private void getModels() {
if (sharedPreferences.getString(getString(R.string.ollama_url_key), null) == null) {
return;
}
URL ollamaURL;
try {
ollamaURL = new URL(sharedPreferences.getString(getString(R.string.ollama_url_key), null));
getModels(new URL(sharedPreferences.getString(getString(R.string.ollama_url_key),"")));
} catch (MalformedURLException e) {
Snackbar.make(findViewById(R.id.editSystemPrompt), "Invalid URL", 2)
.show();
return;
e.printStackTrace();
}
}
private void getModels(URL ollamaURL) {
if(ollamaURL.getHost().equals("")) {
return;
}
Expand Down

0 comments on commit ce6e085

Please sign in to comment.