-
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.
Add LiveData implementation to item list in MainActivity
- Loading branch information
Showing
8 changed files
with
312 additions
and
21 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
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
25 changes: 25 additions & 0 deletions
25
app/src/main/java/io/github/storagereloaded/android/db/dao/ItemDao.java
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,25 @@ | ||
package io.github.storagereloaded.android.db.dao; | ||
|
||
import androidx.lifecycle.LiveData; | ||
import androidx.room.Dao; | ||
import androidx.room.Insert; | ||
import androidx.room.OnConflictStrategy; | ||
import androidx.room.Query; | ||
|
||
import java.util.List; | ||
|
||
import io.github.storagereloaded.android.db.entity.ItemEntity; | ||
|
||
@Dao | ||
public interface ItemDao { | ||
|
||
@Query("SELECT * FROM items WHERE databaseId=:databaseId") | ||
LiveData<List<ItemEntity>> getItemsInDatabase(int databaseId); | ||
|
||
@Query("SELECT * FROM items WHERE id=:itemId") | ||
LiveData<ItemEntity> getItem(int itemId); | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
void insertAll(List<ItemEntity> items); | ||
|
||
} |
134 changes: 134 additions & 0 deletions
134
app/src/main/java/io/github/storagereloaded/android/db/entity/ItemEntity.java
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,134 @@ | ||
package io.github.storagereloaded.android.db.entity; | ||
|
||
import androidx.room.Entity; | ||
import androidx.room.PrimaryKey; | ||
|
||
import java.util.Objects; | ||
|
||
import io.github.storagereloaded.android.model.Item; | ||
|
||
@Entity(tableName = "items") | ||
public class ItemEntity implements Item { | ||
|
||
@PrimaryKey | ||
private int id; | ||
private String name; | ||
private String description; | ||
private String imagePath; | ||
private int locationId; | ||
private int amount; | ||
private long lastEdited; | ||
private long created; | ||
private int databaseId; | ||
|
||
@Override | ||
public int getId() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Override | ||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
@Override | ||
public String getImagePath() { | ||
return imagePath; | ||
} | ||
|
||
@Override | ||
public void setImagePath(String imagePath) { | ||
this.imagePath = imagePath; | ||
} | ||
|
||
@Override | ||
public int getLocationId() { | ||
return locationId; | ||
} | ||
|
||
@Override | ||
public void setLocationId(int locationId) { | ||
this.locationId = locationId; | ||
} | ||
|
||
@Override | ||
public int getAmount() { | ||
return amount; | ||
} | ||
|
||
@Override | ||
public void setAmount(int amount) { | ||
this.amount = amount; | ||
} | ||
|
||
@Override | ||
public long getLastEdited() { | ||
return lastEdited; | ||
} | ||
|
||
@Override | ||
public void setLastEdited(long lastEdited) { | ||
this.lastEdited = lastEdited; | ||
} | ||
|
||
@Override | ||
public long getCreated() { | ||
return created; | ||
} | ||
|
||
@Override | ||
public void setCreated(long created) { | ||
this.created = created; | ||
} | ||
|
||
@Override | ||
public int getDatabaseId() { | ||
return databaseId; | ||
} | ||
|
||
@Override | ||
public void setDatabaseId(int databaseId) { | ||
this.databaseId = databaseId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
ItemEntity that = (ItemEntity) o; | ||
return id == that.id && | ||
locationId == that.locationId && | ||
amount == that.amount && | ||
lastEdited == that.lastEdited && | ||
created == that.created && | ||
databaseId == that.databaseId && | ||
Objects.equals(name, that.name) && | ||
Objects.equals(description, that.description) && | ||
Objects.equals(imagePath, that.imagePath); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, name, description, imagePath, locationId, amount, lastEdited, created, databaseId); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/io/github/storagereloaded/android/model/Item.java
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,39 @@ | ||
package io.github.storagereloaded.android.model; | ||
|
||
public interface Item { | ||
int getId(); | ||
|
||
void setId(int id); | ||
|
||
String getName(); | ||
|
||
void setName(String name); | ||
|
||
String getDescription(); | ||
|
||
void setDescription(String description); | ||
|
||
String getImagePath(); | ||
|
||
void setImagePath(String imagePath); | ||
|
||
int getLocationId(); | ||
|
||
void setLocationId(int locationId); | ||
|
||
int getAmount(); | ||
|
||
void setAmount(int amount); | ||
|
||
long getLastEdited(); | ||
|
||
void setLastEdited(long lastEdited); | ||
|
||
long getCreated(); | ||
|
||
void setCreated(long created); | ||
|
||
int getDatabaseId(); | ||
|
||
void setDatabaseId(int databaseId); | ||
} |
Oops, something went wrong.