Android Open Source - dexedd Dex






From Project

Back to project page dexedd.

License

The source code is released under:

MIT License

If you think the Android project dexedd listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nav.dexedd.persistence.access;
//from   w w w. j av  a  2 s.co  m
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.nav.dexedd.R;
import com.nav.dexedd.model.Pokemon;
import com.nav.dexedd.model.Type;
import com.nav.dexedd.persistence.DexDatabase;

import java.util.ArrayList;
import java.util.List;

/**
 * Dex data access object
 *
 * @author Eduardo Naveda
 * @since 0.0.1
 */
public class Dex extends Access {

    public static enum DexType {

        NATIONAL_DEX(1); // Todo add all dex

        private Integer dexType;

        private DexType(Integer dexType) {
            this.dexType = dexType;
        }

        @Override
        public String toString() {
            return dexType.toString();
        }

    }

    private DexType dexType;

    private Dex(Context context, DexType dexType) {
        super(context);
        this.dexType = dexType;
    }

    /**
     * Creates a dex instance using the default dex type.
     *
     * @param context The application context
     *
     * @return dex instance
     */
    public static Dex create(Context context) {
        database = DexDatabase.getInstance(context).getReadableDatabase();
        DexType dexType = DexType.NATIONAL_DEX; // Todo from preferences
        return new Dex(context, dexType);
    }

    /**
     * Creates a dex instance using a specific dex type.
     *
     * @param context The application context
     * @param dexType The dex type
     *
     * @return dex instance
     */
    public static Dex create(Context context, DexType dexType) {
        database = DexDatabase.getInstance(context).getReadableDatabase();
        return new Dex(context, dexType);
    }

    /**
     * Fetches all Pokmon within the dex instance.
     *
     * @return a list of all the {@link com.nav.dexedd.model.Pokemon} within the dex
     */
    public List<Pokemon> listPokemon() {
        String[] args = {dexType.toString()};
        String query = getContext().getString(R.string.get_dex);
        Cursor cursor = database.rawQuery(query, args);
        List<Pokemon> pokemon = new ArrayList<>();
        while (cursor.moveToNext()) {
            Pokemon pokemonItem = new Pokemon();
            pokemonItem.setId(cursor.getInt(0));
            pokemonItem.setSpeciesId(cursor.getInt(1));
            pokemonItem.setDexNumber(cursor.getInt(2));
            pokemonItem.setName(cursor.getString(3));
            Type primaryType = new Type();
            primaryType.setId(cursor.getInt(4));
            pokemonItem.setPrimaryType(primaryType);
            Integer secondaryTypeId = cursor.getInt(5);
            if (secondaryTypeId != 0) {
                Type secondaryType = new Type();
                secondaryType.setId(secondaryTypeId);
                pokemonItem.setSecondaryType(secondaryType);
            }
            pokemonItem.setCatched(cursor.getInt(6) == 1);
            pokemon.add(pokemonItem);
        }
        cursor.close();
        return pokemon;
    }

    /**
     * Marks a Pokmon species as catched.
     *
     * @param context The application context
     * @param speciesId      The Pokmon species id
     * @param catched Mark as catched or not
     */
    public static void setCatched(Context context, Integer speciesId, boolean catched) {
        SQLiteDatabase database = DexDatabase.getInstance(context).getReadableDatabase();
        String where = "id=?";
        String[] args = {speciesId.toString()};
        ContentValues contentValues = new ContentValues();
        contentValues.put("catched", catched);
        database.update("pokemon_species", contentValues, where, args);
    }

}




Java Source Code List

com.nav.dexedd.activity.DexEntryActivity.java
com.nav.dexedd.activity.Dexedd.java
com.nav.dexedd.activity.MainActivity.java
com.nav.dexedd.activity.SplashActivity.java
com.nav.dexedd.adapter.DexAdapter.java
com.nav.dexedd.adapter.TreeAdapter.java
com.nav.dexedd.fragment.DatabaseInitFragment.java
com.nav.dexedd.fragment.NavigationDrawerFragment.java
com.nav.dexedd.model.Ability.java
com.nav.dexedd.model.EggGroup.java
com.nav.dexedd.model.EvolutionCondition.java
com.nav.dexedd.model.Item.java
com.nav.dexedd.model.Location.java
com.nav.dexedd.model.Move.java
com.nav.dexedd.model.Pokemon.java
com.nav.dexedd.model.Region.java
com.nav.dexedd.model.StatSpread.java
com.nav.dexedd.model.Stat.java
com.nav.dexedd.model.Type.java
com.nav.dexedd.persistence.DexDatabase.java
com.nav.dexedd.persistence.access.Access.java
com.nav.dexedd.persistence.access.DexEntry.java
com.nav.dexedd.persistence.access.Dex.java
com.nav.dexedd.structure.Tree.java
com.nav.dexedd.text.CleanClickableSpan.java
com.nav.dexedd.ui.BetterGridView.java
com.nav.dexedd.ui.BetterScrollView.java
com.nav.dexedd.ui.LabelView.java
com.nav.dexedd.ui.SquareImageView.java
com.nav.dexedd.ui.TreeLayout.java
com.nav.dexedd.ui.TypeTagView.java
com.nav.dexedd.util.AssetUtil.java
com.nav.dexedd.util.ConversionUtil.java
com.nav.dexedd.util.PokemonTextUtil.java
com.nav.dexedd.util.TypeUtil.java