Skip to content

Commit

Permalink
DB helper class renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
DevEmperor committed Jan 29, 2024
1 parent d0a73ae commit 148525f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

import net.devemperor.wristassist.R;
import net.devemperor.wristassist.adapters.ChatAdapter;
import net.devemperor.wristassist.database.ChatHistoryDatabaseHelper;
import net.devemperor.wristassist.database.ChatHistoryModel;
import net.devemperor.wristassist.database.DatabaseHelper;
import net.devemperor.wristassist.items.ChatItem;

import org.json.JSONArray;
Expand Down Expand Up @@ -67,7 +67,7 @@ public class ChatActivity extends Activity {

Vibrator vibrator;

DatabaseHelper databaseHelper;
ChatHistoryDatabaseHelper chatHistoryDatabaseHelper;
SharedPreferences sp;

boolean firstAnswerComplete = false;
Expand Down Expand Up @@ -95,7 +95,7 @@ protected void onCreate(Bundle savedInstanceState) {

vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

databaseHelper = new DatabaseHelper(this);
chatHistoryDatabaseHelper = new ChatHistoryDatabaseHelper(this);
sp = getSharedPreferences("net.devemperor.wristassist", MODE_PRIVATE);

String apiKey = sp.getString("net.devemperor.wristassist.api_key", "noApiKey");
Expand All @@ -116,7 +116,7 @@ protected void onCreate(Bundle savedInstanceState) {

if (getIntent().getLongExtra("net.devemperor.wristassist.chatId", -1) != -1) {
long id = getIntent().getLongExtra("net.devemperor.wristassist.chatId", -1);
titleTv.setText(databaseHelper.getTitle(id));
titleTv.setText(chatHistoryDatabaseHelper.getTitle(id));
titleTv.setVisibility(View.VISIBLE);
saveResetBtn.setVisibility(View.VISIBLE);
saveResetBtn.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.twotone_change_circle_24));
Expand Down Expand Up @@ -194,7 +194,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
titleTv.setVisibility(View.VISIBLE);

try {
id = databaseHelper.add(this, new ChatHistoryModel(-1, content, chatAdapter.getChatItems()));
id = chatHistoryDatabaseHelper.add(this, new ChatHistoryModel(-1, content, chatAdapter.getChatItems()));
} catch (JSONException | IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -214,7 +214,7 @@ public void saveReset(View view) throws JSONException, IOException {
for (int i = chatAdapter.getCount() - 1; i > ((chatAdapter.getItem(0).getChatMessage().getRole().equals(ChatMessageRole.SYSTEM.value())) ? 1 : 0); i--) {
chatAdapter.remove(chatAdapter.getItem(i));
}
databaseHelper.reset(this, id, chatAdapter.getChatItems());
chatHistoryDatabaseHelper.reset(this, id, chatAdapter.getChatItems());
firstAnswerComplete = false;
saveResetBtn.setVisibility(View.GONE);
Toast.makeText(this, R.string.wristassist_chat_reset, Toast.LENGTH_SHORT).show();
Expand All @@ -239,7 +239,7 @@ private void query(String query) throws JSONException, IOException {
ChatItem userItem = new ChatItem(new ChatMessage("user", query), 0);
chatAdapter.add(userItem);
if (saveThisChat) {
databaseHelper.edit(this, id, userItem);
chatHistoryDatabaseHelper.edit(this, id, userItem);
}
}

Expand Down Expand Up @@ -274,7 +274,7 @@ private void query(String query) throws JSONException, IOException {
return;
}
if (saveThisChat) {
databaseHelper.edit(this, id, assistantItem);
chatHistoryDatabaseHelper.edit(this, id, assistantItem);
}
runOnUiThread(() -> {
if (sp.getBoolean("net.devemperor.wristassist.vibrate", true)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import android.widget.Toast;

import net.devemperor.wristassist.R;
import net.devemperor.wristassist.database.DatabaseHelper;
import net.devemperor.wristassist.database.ChatHistoryDatabaseHelper;
import net.devemperor.wristassist.util.Util;

import org.json.JSONException;
Expand All @@ -27,7 +27,7 @@ public class EditChatActivity extends Activity {
ImageButton editTitleBtn;
ImageButton deleteChatBtn;

DatabaseHelper databaseHelper;
ChatHistoryDatabaseHelper chatHistoryDatabaseHelper;
long id;
DecimalFormat df = new DecimalFormat("#.##");

Expand All @@ -42,18 +42,18 @@ protected void onCreate(Bundle savedInstanceState) {
editTitleBtn = findViewById(R.id.edit_btn);
deleteChatBtn = findViewById(R.id.delete_btn);

databaseHelper = new DatabaseHelper(this);
chatHistoryDatabaseHelper = new ChatHistoryDatabaseHelper(this);
id = getIntent().getLongExtra("net.devemperor.wristassist.chatId", -1);

titleTv.setText(databaseHelper.getTitle(id));
titleTv.setText(chatHistoryDatabaseHelper.getTitle(id));
titleTv.setTextSize(16 * Util.getFontMultiplier(this));

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss", Locale.getDefault());
modifiedTv.setText(formatter.format(databaseHelper.getModified(id)));
modifiedTv.setText(formatter.format(chatHistoryDatabaseHelper.getModified(id)));
modifiedTv.setTextSize(14 * Util.getFontMultiplier(this));

try {
chatCostTv.setText(getString(R.string.wristassist_chat_cost, df.format(databaseHelper.getChatCost(this, id) / 1000.0)));
chatCostTv.setText(getString(R.string.wristassist_chat_cost, df.format(chatHistoryDatabaseHelper.getChatCost(this, id) / 1000.0)));
chatCostTv.setTextSize(14 * Util.getFontMultiplier(this));
} catch (IOException | JSONException e) {
throw new RuntimeException(e);
Expand All @@ -67,7 +67,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) return;
if (requestCode == 1337) {
String content = data.getStringExtra("net.devemperor.wristassist.input.content");
databaseHelper.setTitle(id, content);
chatHistoryDatabaseHelper.setTitle(id, content);
titleTv.setText(content);
}
}
Expand All @@ -80,7 +80,7 @@ public void editTitle(View view) {
}

public void deleteChat(View view) {
databaseHelper.delete(this, id);
chatHistoryDatabaseHelper.delete(this, id);
Toast.makeText(this, R.string.wristassist_chat_deleted, Toast.LENGTH_SHORT).show();
finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import net.devemperor.wristassist.R;
import net.devemperor.wristassist.adapters.SavedChatsAdapter;
import net.devemperor.wristassist.database.ChatHistoryDatabaseHelper;
import net.devemperor.wristassist.database.ChatHistoryModel;
import net.devemperor.wristassist.database.DatabaseHelper;
import net.devemperor.wristassist.util.Util;

import java.util.List;
Expand All @@ -24,7 +24,7 @@ public class SavedChatsActivity extends Activity {

WearableRecyclerView savedChatsWrv;

DatabaseHelper databaseHelper;
ChatHistoryDatabaseHelper chatHistoryDatabaseHelper;
SavedChatsAdapter savedChatsAdapter;

@Override
Expand All @@ -37,8 +37,8 @@ protected void onCreate(Bundle savedInstanceState) {
savedChatsWrv.setEdgeItemsCenteringEnabled(true);
savedChatsWrv.setLayoutManager(new WearableLinearLayoutManager(this));

databaseHelper = new DatabaseHelper(this);
List<ChatHistoryModel> chats = databaseHelper.getAllChats();
chatHistoryDatabaseHelper = new ChatHistoryDatabaseHelper(this);
List<ChatHistoryModel> chats = chatHistoryDatabaseHelper.getAllChats();

savedChatsAdapter = new SavedChatsAdapter(chats, (chatPosition, longClick) -> {
Intent intent;
Expand Down Expand Up @@ -71,7 +71,7 @@ protected void onCreate(Bundle savedInstanceState) {
protected void onResume() {
super.onResume();
savedChatsAdapter.getData().clear();
savedChatsAdapter.getData().addAll(databaseHelper.getAllChats());
savedChatsAdapter.getData().addAll(chatHistoryDatabaseHelper.getAllChats());
savedChatsAdapter.notifyDataSetChanged();

findViewById(R.id.no_saved_chats).setVisibility(savedChatsAdapter.getData().isEmpty() ? android.view.View.VISIBLE : android.view.View.GONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.util.List;
import java.util.Objects;

public class DatabaseHelper extends SQLiteOpenHelper {
public class ChatHistoryDatabaseHelper extends SQLiteOpenHelper {

private final Context context;

public DatabaseHelper(@Nullable Context context) {
public ChatHistoryDatabaseHelper(@Nullable Context context) {
super(context, "chatHistory.db", null, 3);
this.context = context;
}
Expand Down

0 comments on commit 148525f

Please sign in to comment.