Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import android.content.Context;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;

public class ExceptionHandler {
public void handleException(Context context, Exception exception) {
if (exception instanceof RedisException) {
Log.e("ExceptionHandler", "RedisException occurred", exception);
// Prevent note content from being replaced with error message
String noteContent = "Note content not available";
} else {
// Handle other exceptions
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;

public class ItemAdapter extends RecyclerView.Adapter<ItemAdapter.ViewHolder> {
private NotesDatabase database;

public ItemAdapter(Context context) {
database = NotesDatabase.getInstance(context);
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout, parent, false);
return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
try {
// Load note content from database
String noteContent = database.getNoteContent();
holder.textView.setText(noteContent);
} catch (RedisException e) {
Log.e("ItemAdapter", "RedisException occurred", e);
// Prevent note content from being replaced with error message
holder.textView.setText("Note content not available");
}
}

public class ViewHolder extends RecyclerView.ViewHolder {
public TextView textView;

public ViewHolder(View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.text_view);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import it.niedermann.owncloud.notes.persistence.NotesDatabase;

public class MainActivity extends AppCompatActivity {
private NotesDatabase database;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
database = NotesDatabase.getInstance(this);

try {
// Load note content from database
String noteContent = database.getNoteContent();
} catch (RedisException e) {
Log.e("MainActivity", "RedisException occurred", e);
// Prevent note content from being replaced with error message
String noteContent = "Note content not available";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import androidx.room.Entity;
import androidx.room.PrimaryKey;

@Entity
public class Note {
@PrimaryKey
public int id;
public String content;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import androidx.room.Dao;
import androidx.room.Query;
import it.niedermann.owncloud.notes.persistence.Note;

@Dao
public interface NoteDao {
@Query("SELECT * FROM notes")
List<Note> getNotes();

@Query("SELECT content FROM notes WHERE id = :id")
String getNoteContent(int id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import it.niedermann.owncloud.notes.persistence.NoteDao;

@Database(entities = {Note.class}, version = 1)
public abstract class NotesDatabase extends RoomDatabase {
public abstract NoteDao noteDao();

private static NotesDatabase INSTANCE;

public static synchronized NotesDatabase getInstance(Context context) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(), NotesDatabase.class, "notes_database")
.build();
}
return INSTANCE;
}
}