forked from MetallicFocus/team_zero_application
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented local database (chat list table with associated CRUD oper…
…ations) and additon and deletion of chats from chat list
- Loading branch information
Tiberiu Iustin Zulean
committed
Nov 13, 2019
1 parent
f64260e
commit 399c0b1
Showing
11 changed files
with
310 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package database; | ||
|
||
import android.arch.persistence.room.Database; | ||
import android.arch.persistence.room.RoomDatabase; | ||
|
||
@Database(entities = {StoredChatList.class}, version = 1) | ||
public abstract class AppDatabase extends RoomDatabase { | ||
public abstract StoredChatListDao storedChatListDao(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package database; | ||
|
||
import android.arch.persistence.room.Room; | ||
import android.content.Context; | ||
|
||
public class AppDatabaseClient { | ||
|
||
private Context mCtx; | ||
private static AppDatabaseClient mInstance; | ||
|
||
private AppDatabase appDatabase; | ||
|
||
private AppDatabaseClient(Context mCtx) { | ||
|
||
this.mCtx = mCtx; | ||
|
||
appDatabase = Room.databaseBuilder(mCtx, AppDatabase.class, "MyToDos").build(); | ||
} | ||
|
||
public static synchronized AppDatabaseClient getInstance(Context mCtx) { | ||
if (mInstance == null) { | ||
mInstance = new AppDatabaseClient(mCtx); | ||
} | ||
return mInstance; | ||
} | ||
|
||
public AppDatabase getAppDatabase() { | ||
return appDatabase; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package database; | ||
|
||
import android.arch.persistence.room.ColumnInfo; | ||
import android.arch.persistence.room.Entity; | ||
import android.arch.persistence.room.PrimaryKey; | ||
|
||
import java.io.Serializable; | ||
|
||
@Entity | ||
public class StoredChatList implements Serializable { | ||
|
||
@PrimaryKey(autoGenerate = true) | ||
private int id; | ||
|
||
@ColumnInfo(name = "username") | ||
private String username; | ||
|
||
@ColumnInfo(name = "last_message_content") | ||
private String lastMessageContent; | ||
|
||
@ColumnInfo(name = "last_message_date") | ||
private String lastMessageDate; | ||
|
||
/* * | ||
* | ||
* Getters and Setters | ||
* | ||
* */ | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public void setUsername(String username) { | ||
this.username = username; | ||
} | ||
|
||
public String getLastMessageContent() { | ||
return lastMessageContent; | ||
} | ||
|
||
public void setLastMessageContent(String lastMessageContent) { | ||
this.lastMessageContent = lastMessageContent; | ||
} | ||
|
||
public String getLastMessageDate() { | ||
return lastMessageDate; | ||
} | ||
|
||
public void setLastMessageDate(String messageDate) { | ||
this.lastMessageDate = lastMessageDate; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package database; | ||
|
||
import android.arch.persistence.room.Dao; | ||
import android.arch.persistence.room.Delete; | ||
import android.arch.persistence.room.Insert; | ||
import android.arch.persistence.room.Query; | ||
import android.arch.persistence.room.Update; | ||
|
||
import java.util.List; | ||
|
||
// Interface for the CRUD operations on StoredChatList table | ||
|
||
@Dao | ||
public interface StoredChatListDao { | ||
|
||
@Query("SELECT * FROM storedchatlist") | ||
List<StoredChatList> getAll(); | ||
|
||
@Query("DELETE FROM storedchatlist") | ||
void deleteAll(); | ||
|
||
@Insert | ||
void insert(StoredChatList storedChatList); | ||
|
||
@Delete | ||
void delete(StoredChatList storedChatList); | ||
|
||
@Update | ||
void update(StoredChatList storedChatList); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.