-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#341# Arranging Package Design # Creating new database in MVVM archit…
…ecture # Using Dependency Injection # Using not hard-coded variable names # Using Coroutine # Using ViewModel #Add new dependencies on gradle files#
- Loading branch information
egecan.serbester
committed
Oct 22, 2023
1 parent
6008b3a
commit 5bfc4cf
Showing
27 changed files
with
415 additions
and
50 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
13 changes: 13 additions & 0 deletions
13
...esponsePlatform/app/src/main/java/com/example/disasterresponseplatform/DarpApplication.kt
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,13 @@ | ||
package com.example.disasterresponseplatform | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
/** This is for Hilt | ||
* It basically for hold the ActivationContext on Hilt, thanks to this class whenever Hilt needs an ActivationContext | ||
* it comes from there | ||
* Warning: You need to add Manifest because it's an activity otherwise you will get an error | ||
*/ | ||
@HiltAndroidApp | ||
class DarpApplication: Application() { | ||
} |
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
5 changes: 0 additions & 5 deletions
5
...onsePlatform/app/src/main/java/com/example/disasterresponseplatform/data/DummyActivity.kt
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
...sePlatform/app/src/main/java/com/example/disasterresponseplatform/data/database/DarpDB.kt
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 com.example.disasterresponseplatform.data.database | ||
|
||
import android.content.Context | ||
import androidx.room.AutoMigration | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import androidx.room.migration.Migration | ||
import com.example.disasterresponseplatform.data.database.need.Need | ||
import com.example.disasterresponseplatform.data.database.need.NeedDao | ||
|
||
@Database(entities = [Need::class], version = DatabaseInfo.DATABASE_VERSION, exportSchema = false) | ||
abstract class DarpDB: RoomDatabase() { | ||
abstract val needDao: NeedDao | ||
|
||
// it's static object in this way you can call getInstance method without any initialization | ||
companion object{ | ||
@Volatile //this makes this field visible to other threads | ||
private var firstInstance: DarpDB? = null | ||
|
||
fun getInstance(context: Context): DarpDB { | ||
synchronized(this) { | ||
var instance = firstInstance | ||
if (instance == null) { | ||
instance = Room.databaseBuilder( | ||
context.applicationContext, | ||
DarpDB::class.java, DatabaseInfo.DATABASE | ||
) | ||
.allowMainThreadQueries() | ||
.fallbackToDestructiveMigration() // when migrate a new version delete the existing db | ||
.build() | ||
firstInstance = instance | ||
} | ||
return instance | ||
} | ||
} | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...form/app/src/main/java/com/example/disasterresponseplatform/data/database/DatabaseInfo.kt
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,16 @@ | ||
package com.example.disasterresponseplatform.data.database | ||
|
||
/** | ||
* This is for holding data in regular way. | ||
*/ | ||
class DatabaseInfo { | ||
companion object { | ||
const val DATABASE: String = "DARP_DB" | ||
const val ACTION: String = "ACTION" | ||
const val EMERGENCY: String = "EMERGENCY" | ||
const val EVENT: String = "EVENT" | ||
const val NEED: String = "NEED" | ||
const val RESOURCE: String = "RESOURCE" | ||
const val DATABASE_VERSION: Int = 2 // you need to change that whenever you change any table on DB | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...latform/app/src/main/java/com/example/disasterresponseplatform/data/database/need/Need.kt
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,27 @@ | ||
package com.example.disasterresponseplatform.data.database.need | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.example.disasterresponseplatform.data.database.DatabaseInfo | ||
|
||
@Entity(tableName = DatabaseInfo.NEED) | ||
data class Need( | ||
@PrimaryKey(autoGenerate = true) | ||
@ColumnInfo (name = NeedCols.id) | ||
val ID: Int?, // if user does not enter ID, it generates it automatically | ||
@ColumnInfo(name = NeedCols.creatorID) | ||
val creatorID: String, | ||
@ColumnInfo(name = NeedCols.type) | ||
val type: String, | ||
@ColumnInfo(name = NeedCols.subTypeList) | ||
val subType: String, | ||
@ColumnInfo(name = NeedCols.creationTime) | ||
val creationTime: String?, | ||
@ColumnInfo(name = NeedCols.quantity) | ||
val quantity: Int?, | ||
@ColumnInfo(name = NeedCols.location) | ||
val location: String?, | ||
@ColumnInfo(name = NeedCols.urgency) | ||
val urgency: Int? | ||
) |
16 changes: 16 additions & 0 deletions
16
...orm/app/src/main/java/com/example/disasterresponseplatform/data/database/need/NeedCols.kt
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,16 @@ | ||
package com.example.disasterresponseplatform.data.database.need | ||
|
||
class NeedCols { | ||
|
||
companion object{ | ||
const val id: String = "id" | ||
const val type: String = "type" | ||
const val subTypeList: String = "subTypeList" | ||
const val creationTime: String = "creationTime" | ||
const val creatorID: String = "creatorID" | ||
const val location: String = "location" | ||
const val quantity: String = "quantity" | ||
const val urgency: String = "urgency" | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...form/app/src/main/java/com/example/disasterresponseplatform/data/database/need/NeedDao.kt
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,15 @@ | ||
package com.example.disasterresponseplatform.data.database.need | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import com.example.disasterresponseplatform.data.database.DatabaseInfo | ||
|
||
@Dao | ||
interface NeedDao { | ||
@Insert | ||
suspend fun insertActivation(need: Need) | ||
|
||
@Query("SELECT ${NeedCols.location} FROM ${DatabaseInfo.NEED} WHERE ${NeedCols.creatorID} = :creatorID") | ||
fun getLocation(creatorID: String): String | ||
} |
2 changes: 1 addition & 1 deletion
2
...sterresponseplatform/data/ActivityEnum.kt → ...sponseplatform/data/enums/ActivityEnum.kt
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
7 changes: 7 additions & 0 deletions
7
...nsePlatform/app/src/main/java/com/example/disasterresponseplatform/data/enums/EndPoint.kt
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,7 @@ | ||
package com.example.disasterresponseplatform.data.enums | ||
|
||
enum class Endpoint(val path: String) { | ||
DATA("joke/any"), | ||
USER("user"), | ||
PRODUCTS("products"); | ||
} |
2 changes: 1 addition & 1 deletion
2
...rresponseplatform/data/PredefinedTypes.kt → ...nseplatform/data/enums/PredefinedTypes.kt
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
5 changes: 5 additions & 0 deletions
5
...Platform/app/src/main/java/com/example/disasterresponseplatform/data/enums/RequestType.kt
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,5 @@ | ||
package com.example.disasterresponseplatform.data.enums | ||
|
||
enum class RequestType { | ||
GET, POST, PUT, DELETE // Add more HTTP methods as needed | ||
} |
10 changes: 10 additions & 0 deletions
10
...onsePlatform/app/src/main/java/com/example/disasterresponseplatform/data/enums/Urgency.kt
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,10 @@ | ||
package com.example.disasterresponseplatform.data.enums | ||
|
||
enum class Urgency(val type: Int) { | ||
EMERGENCY(0), | ||
CRITICAL(1), | ||
URGENT(2), | ||
HIGH_PRIORITY(3), | ||
NORMAL_PRIORITY(4), | ||
LOW_PRIORITY(5) | ||
} |
8 changes: 8 additions & 0 deletions
8
...tform/app/src/main/java/com/example/disasterresponseplatform/data/models/DummyActivity.kt
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,8 @@ | ||
package com.example.disasterresponseplatform.data.models | ||
|
||
import com.example.disasterresponseplatform.data.enums.ActivityEnum | ||
import com.example.disasterresponseplatform.data.enums.PredefinedTypes | ||
|
||
class DummyActivity(var activityType: ActivityEnum, var predefinedTypes: PredefinedTypes, var location: String, | ||
var date: String, var reliabilityScale: Double) { | ||
} |
17 changes: 17 additions & 0 deletions
17
...pp/src/main/java/com/example/disasterresponseplatform/data/repositories/NeedRepository.kt
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,17 @@ | ||
package com.example.disasterresponseplatform.data.repositories | ||
|
||
import com.example.disasterresponseplatform.data.database.need.Need | ||
import com.example.disasterresponseplatform.data.database.need.NeedDao | ||
import javax.inject.Inject | ||
|
||
class NeedRepository @Inject constructor(private val needDao: NeedDao) { | ||
|
||
suspend fun insertNeed(need: Need){ | ||
needDao.insertActivation(need) | ||
} | ||
|
||
fun getLocation(creatorID: String): String{ | ||
return needDao.getLocation(creatorID) | ||
} | ||
|
||
} |
Oops, something went wrong.