Skip to content

Commit 770426e

Browse files
committed
Prepare storing static data in db
1 parent f2e71e2 commit 770426e

7 files changed

+139
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package de.g00fy2.model.entities.db;
2+
3+
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
4+
import com.raizlabs.android.dbflow.annotation.Table;
5+
import de.g00fy2.model.db.AppDatabase;
6+
7+
/**
8+
* Created by Thomas Wirth on 09.12.2017.
9+
*/
10+
11+
@Table(database = AppDatabase.class, allFields = true) public class ChampionDbEntity {
12+
13+
public String name;
14+
public String title;
15+
public String key;
16+
@PrimaryKey public int id;
17+
18+
@Override public String toString() {
19+
return "ChampionDbEntity{"
20+
+ "name='"
21+
+ name
22+
+ '\''
23+
+ ", title='"
24+
+ title
25+
+ '\''
26+
+ ", key='"
27+
+ key
28+
+ '\''
29+
+ ", id="
30+
+ id
31+
+ '}';
32+
}
33+
}

model/src/main/java/de/g00fy2/model/entities/db/SummonerDbEntity.java

+18
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,22 @@
1616
public long revisionDate;
1717
@PrimaryKey public long id;
1818
public long accountId;
19+
20+
@Override public String toString() {
21+
return "SummonerDbEntity{"
22+
+ "profileIconId="
23+
+ profileIconId
24+
+ ", name='"
25+
+ name
26+
+ '\''
27+
+ ", summonerLevel="
28+
+ summonerLevel
29+
+ ", revisionDate="
30+
+ revisionDate
31+
+ ", id="
32+
+ id
33+
+ ", accountId="
34+
+ accountId
35+
+ '}';
36+
}
1937
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package de.g00fy2.model.entities.db;
2+
3+
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
4+
import com.raizlabs.android.dbflow.annotation.Table;
5+
import de.g00fy2.model.db.AppDatabase;
6+
7+
/**
8+
* Created by Thomas Wirth on 09.12.2017.
9+
*/
10+
11+
@Table(database = AppDatabase.class, allFields = true) public class SummonerSpellDbEntity {
12+
13+
@PrimaryKey public int id;
14+
public int summonerLevel;
15+
public String name;
16+
public String key;
17+
public String description;
18+
19+
@Override public String toString() {
20+
return "SummonerSpellDbEntity{"
21+
+ "id="
22+
+ id
23+
+ ", summonerLevel="
24+
+ summonerLevel
25+
+ ", name='"
26+
+ name
27+
+ '\''
28+
+ ", key='"
29+
+ key
30+
+ '\''
31+
+ ", description='"
32+
+ description
33+
+ '\''
34+
+ '}';
35+
}
36+
}

model/src/main/java/de/g00fy2/model/transformers/ChampionListTransformer.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package de.g00fy2.model.transformers;
22

3+
import de.g00fy2.model.entities.db.ChampionDbEntity;
34
import de.g00fy2.model.entities.web.ChampionListWebEntity;
45
import de.g00fy2.model.models.Champion;
6+
import java.util.List;
57
import java.util.Map;
68

79
/**
@@ -11,4 +13,6 @@
1113
public interface ChampionListTransformer {
1214

1315
Map<Integer, Champion> toModel(ChampionListWebEntity championListWebEntity);
16+
17+
Map<Integer, Champion> toModel(List<ChampionDbEntity> championDbEntities);
1418
}

model/src/main/java/de/g00fy2/model/transformers/ChampionListTransformerImpl.java

+20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package de.g00fy2.model.transformers;
22

3+
import de.g00fy2.model.entities.db.ChampionDbEntity;
34
import de.g00fy2.model.entities.web.ChampionListWebEntity;
45
import de.g00fy2.model.entities.web.ChampionWebEntity;
56
import de.g00fy2.model.models.Champion;
67
import java.util.HashMap;
8+
import java.util.List;
79
import java.util.Map;
810
import javax.inject.Inject;
911

@@ -34,4 +36,22 @@ public class ChampionListTransformerImpl implements ChampionListTransformer {
3436

3537
return null;
3638
}
39+
40+
@Override public Map<Integer, Champion> toModel(List<ChampionDbEntity> championDbEntities) {
41+
if (championDbEntities != null && championDbEntities.size() > 0) {
42+
Map<Integer, Champion> championMap = new HashMap<>();
43+
for (ChampionDbEntity championDbEntity : championDbEntities) {
44+
Champion champion = new Champion();
45+
champion.name = championDbEntity.name;
46+
champion.title = championDbEntity.title;
47+
champion.key = championDbEntity.key;
48+
champion.id = championDbEntity.id;
49+
championMap.put(champion.id, champion);
50+
}
51+
52+
return championMap;
53+
}
54+
55+
return null;
56+
}
3757
}

model/src/main/java/de/g00fy2/model/transformers/SummonerSpellTransformer.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package de.g00fy2.model.transformers;
22

3+
import de.g00fy2.model.entities.db.SummonerSpellDbEntity;
34
import de.g00fy2.model.entities.web.SummonerSpellListWebEntity;
45
import de.g00fy2.model.models.SummonerSpell;
6+
import java.util.List;
57
import java.util.Map;
68

79
/**
@@ -11,4 +13,6 @@
1113
public interface SummonerSpellTransformer {
1214

1315
Map<Integer, SummonerSpell> toModel(SummonerSpellListWebEntity summonerSpellListWebEntity);
16+
17+
Map<Integer, SummonerSpell> toModel(List<SummonerSpellDbEntity> summonerSpellDbEntities);
1418
}

model/src/main/java/de/g00fy2/model/transformers/SummonerSpellTransformerImpl.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package de.g00fy2.model.transformers;
22

3+
import de.g00fy2.model.entities.db.SummonerSpellDbEntity;
34
import de.g00fy2.model.entities.web.SummonerSpellListWebEntity;
45
import de.g00fy2.model.entities.web.SummonerSpellWebEntity;
56
import de.g00fy2.model.models.SummonerSpell;
67
import java.util.HashMap;
8+
import java.util.List;
79
import java.util.Map;
810
import javax.inject.Inject;
911

@@ -29,7 +31,28 @@ public Map<Integer, SummonerSpell> toModel(SummonerSpellListWebEntity summonerSp
2931
summonerSpell.key = summonerSpellWebEntity1.key;
3032
summonerSpell.description = summonerSpellWebEntity1.description;
3133

32-
summonerSpellMap.put(summonerSpellWebEntity1.id, summonerSpell);
34+
summonerSpellMap.put(summonerSpell.id, summonerSpell);
35+
}
36+
37+
return summonerSpellMap;
38+
}
39+
40+
return null;
41+
}
42+
43+
@Override
44+
public Map<Integer, SummonerSpell> toModel(List<SummonerSpellDbEntity> summonerSpellDbEntities) {
45+
if (summonerSpellDbEntities != null && summonerSpellDbEntities.size() > 0) {
46+
Map<Integer, SummonerSpell> summonerSpellMap = new HashMap<>();
47+
for (SummonerSpellDbEntity summonerDbEntities : summonerSpellDbEntities) {
48+
SummonerSpell summonerSpell = new SummonerSpell();
49+
summonerSpell.id = summonerDbEntities.id;
50+
summonerSpell.summonerLevel = summonerDbEntities.summonerLevel;
51+
summonerSpell.name = summonerDbEntities.name;
52+
summonerSpell.key = summonerDbEntities.key;
53+
summonerSpell.description = summonerDbEntities.description;
54+
55+
summonerSpellMap.put(summonerSpell.id, summonerSpell);
3356
}
3457

3558
return summonerSpellMap;

0 commit comments

Comments
 (0)