Skip to content

Commit

Permalink
Prepare storing static data in db
Browse files Browse the repository at this point in the history
  • Loading branch information
G00fY2 committed Dec 9, 2017
1 parent f2e71e2 commit 770426e
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package de.g00fy2.model.entities.db;

import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import de.g00fy2.model.db.AppDatabase;

/**
* Created by Thomas Wirth on 09.12.2017.
*/

@Table(database = AppDatabase.class, allFields = true) public class ChampionDbEntity {

public String name;
public String title;
public String key;
@PrimaryKey public int id;

@Override public String toString() {
return "ChampionDbEntity{"
+ "name='"
+ name
+ '\''
+ ", title='"
+ title
+ '\''
+ ", key='"
+ key
+ '\''
+ ", id="
+ id
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,22 @@
public long revisionDate;
@PrimaryKey public long id;
public long accountId;

@Override public String toString() {
return "SummonerDbEntity{"
+ "profileIconId="
+ profileIconId
+ ", name='"
+ name
+ '\''
+ ", summonerLevel="
+ summonerLevel
+ ", revisionDate="
+ revisionDate
+ ", id="
+ id
+ ", accountId="
+ accountId
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package de.g00fy2.model.entities.db;

import com.raizlabs.android.dbflow.annotation.PrimaryKey;
import com.raizlabs.android.dbflow.annotation.Table;
import de.g00fy2.model.db.AppDatabase;

/**
* Created by Thomas Wirth on 09.12.2017.
*/

@Table(database = AppDatabase.class, allFields = true) public class SummonerSpellDbEntity {

@PrimaryKey public int id;
public int summonerLevel;
public String name;
public String key;
public String description;

@Override public String toString() {
return "SummonerSpellDbEntity{"
+ "id="
+ id
+ ", summonerLevel="
+ summonerLevel
+ ", name='"
+ name
+ '\''
+ ", key='"
+ key
+ '\''
+ ", description='"
+ description
+ '\''
+ '}';
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package de.g00fy2.model.transformers;

import de.g00fy2.model.entities.db.ChampionDbEntity;
import de.g00fy2.model.entities.web.ChampionListWebEntity;
import de.g00fy2.model.models.Champion;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -11,4 +13,6 @@
public interface ChampionListTransformer {

Map<Integer, Champion> toModel(ChampionListWebEntity championListWebEntity);

Map<Integer, Champion> toModel(List<ChampionDbEntity> championDbEntities);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.g00fy2.model.transformers;

import de.g00fy2.model.entities.db.ChampionDbEntity;
import de.g00fy2.model.entities.web.ChampionListWebEntity;
import de.g00fy2.model.entities.web.ChampionWebEntity;
import de.g00fy2.model.models.Champion;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;

Expand Down Expand Up @@ -34,4 +36,22 @@ public class ChampionListTransformerImpl implements ChampionListTransformer {

return null;
}

@Override public Map<Integer, Champion> toModel(List<ChampionDbEntity> championDbEntities) {
if (championDbEntities != null && championDbEntities.size() > 0) {
Map<Integer, Champion> championMap = new HashMap<>();
for (ChampionDbEntity championDbEntity : championDbEntities) {
Champion champion = new Champion();
champion.name = championDbEntity.name;
champion.title = championDbEntity.title;
champion.key = championDbEntity.key;
champion.id = championDbEntity.id;
championMap.put(champion.id, champion);
}

return championMap;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package de.g00fy2.model.transformers;

import de.g00fy2.model.entities.db.SummonerSpellDbEntity;
import de.g00fy2.model.entities.web.SummonerSpellListWebEntity;
import de.g00fy2.model.models.SummonerSpell;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -11,4 +13,6 @@
public interface SummonerSpellTransformer {

Map<Integer, SummonerSpell> toModel(SummonerSpellListWebEntity summonerSpellListWebEntity);

Map<Integer, SummonerSpell> toModel(List<SummonerSpellDbEntity> summonerSpellDbEntities);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package de.g00fy2.model.transformers;

import de.g00fy2.model.entities.db.SummonerSpellDbEntity;
import de.g00fy2.model.entities.web.SummonerSpellListWebEntity;
import de.g00fy2.model.entities.web.SummonerSpellWebEntity;
import de.g00fy2.model.models.SummonerSpell;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;

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

summonerSpellMap.put(summonerSpellWebEntity1.id, summonerSpell);
summonerSpellMap.put(summonerSpell.id, summonerSpell);
}

return summonerSpellMap;
}

return null;
}

@Override
public Map<Integer, SummonerSpell> toModel(List<SummonerSpellDbEntity> summonerSpellDbEntities) {
if (summonerSpellDbEntities != null && summonerSpellDbEntities.size() > 0) {
Map<Integer, SummonerSpell> summonerSpellMap = new HashMap<>();
for (SummonerSpellDbEntity summonerDbEntities : summonerSpellDbEntities) {
SummonerSpell summonerSpell = new SummonerSpell();
summonerSpell.id = summonerDbEntities.id;
summonerSpell.summonerLevel = summonerDbEntities.summonerLevel;
summonerSpell.name = summonerDbEntities.name;
summonerSpell.key = summonerDbEntities.key;
summonerSpell.description = summonerDbEntities.description;

summonerSpellMap.put(summonerSpell.id, summonerSpell);
}

return summonerSpellMap;
Expand Down

0 comments on commit 770426e

Please sign in to comment.