└── app └── src └── main └── java └── com └── jixa └── converter ├── WordLevel.java ├── User.java ├── TestWord.java ├── Sentence.java ├── IntPair.java ├── Collection.java ├── Exam.java ├── ReviewableWord.java ├── MainActivity.java ├── RealmHelper.java ├── SqliteToRealm.java ├── Course.java ├── Word.java └── SqliteHelper.java /app/src/main/java/com/jixa/converter/WordLevel.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | public abstract class WordLevel { 5 | public static final int BEGINNER = 0; 6 | public static final int MEDIUM = 1; 7 | public static final int EXPERT = 2; 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/User.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | import io.realm.RealmObject; 5 | import io.realm.annotations.PrimaryKey; 6 | 7 | public class User extends RealmObject{ 8 | 9 | @PrimaryKey 10 | private int id; 11 | 12 | private String name; 13 | 14 | public int getId() { 15 | return id; 16 | } 17 | 18 | public void setId(int id) { 19 | this.id = id; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/TestWord.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | import io.realm.RealmObject; 5 | import io.realm.annotations.PrimaryKey; 6 | 7 | public class TestWord extends RealmObject{ 8 | 9 | @PrimaryKey 10 | private int id; 11 | 12 | private String word; 13 | 14 | public int getId() { 15 | return id; 16 | } 17 | 18 | public void setId(int id) { 19 | this.id = id; 20 | } 21 | 22 | public String getWord() { 23 | return word; 24 | } 25 | 26 | public void setWord(String word) { 27 | this.word = word; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/Sentence.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | import io.realm.RealmObject; 5 | import io.realm.annotations.PrimaryKey; 6 | 7 | 8 | public class Sentence extends RealmObject { 9 | 10 | @PrimaryKey 11 | private int id; 12 | 13 | private String text; 14 | 15 | public int getId() { 16 | return id; 17 | } 18 | 19 | public void setId(int id) { 20 | this.id = id; 21 | } 22 | 23 | public String getText() { 24 | return text; 25 | } 26 | 27 | public void setText(String text) { 28 | this.text = text; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/IntPair.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | public class IntPair { 5 | private int firstVal; 6 | private int socondVal; 7 | 8 | public IntPair(int firstVal, int socondVal) { 9 | this.firstVal = firstVal; 10 | this.socondVal = socondVal; 11 | } 12 | 13 | public int getFirstVal() { 14 | return firstVal; 15 | } 16 | 17 | public void setFirstVal(int firstVal) { 18 | this.firstVal = firstVal; 19 | } 20 | 21 | public int getSocondVal() { 22 | return socondVal; 23 | } 24 | 25 | public void setSocondVal(int socondVal) { 26 | this.socondVal = socondVal; 27 | } 28 | 29 | @Override 30 | public String toString(){ 31 | return "VALUES: " +firstVal + " -- " + socondVal; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/Collection.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | import io.realm.RealmList; 5 | import io.realm.RealmObject; 6 | import io.realm.annotations.PrimaryKey; 7 | 8 | 9 | public class Collection extends RealmObject{ 10 | 11 | @PrimaryKey 12 | private int id; 13 | 14 | private String name; 15 | 16 | private int extra; 17 | 18 | private RealmList words; 19 | 20 | public Collection(){} 21 | 22 | public int getId() { 23 | return id; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public int getExtra() { 39 | return extra; 40 | } 41 | 42 | public void setExtra(int extra) { 43 | this.extra = extra; 44 | } 45 | 46 | public RealmList getWords() { 47 | return words; 48 | } 49 | 50 | public void setWords(RealmList words) { 51 | this.words = words; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/Exam.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | import io.realm.RealmList; 5 | import io.realm.RealmObject; 6 | import io.realm.annotations.PrimaryKey; 7 | 8 | public class Exam extends RealmObject { 9 | 10 | @PrimaryKey 11 | private int id; 12 | 13 | private String name; 14 | 15 | private String description; 16 | 17 | private RealmList collections; 18 | 19 | public int getId() { 20 | return id; 21 | } 22 | 23 | public void setId(int id) { 24 | this.id = id; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public String getDescription() { 36 | return description; 37 | } 38 | 39 | public void setDescription(String description) { 40 | this.description = description; 41 | } 42 | 43 | public RealmList getCollections() { 44 | return collections; 45 | } 46 | 47 | public void setCollections(RealmList collections) { 48 | this.collections = collections; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/ReviewableWord.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | import java.util.Date; 5 | import io.realm.RealmObject; 6 | import io.realm.annotations.PrimaryKey; 7 | 8 | public class ReviewableWord extends RealmObject{ 9 | 10 | @PrimaryKey 11 | private int id; 12 | 13 | private Word word; 14 | 15 | private long nextReview; 16 | 17 | private int stage; 18 | 19 | public ReviewableWord (){} 20 | 21 | public ReviewableWord(Word word){ 22 | this.setWord(word); 23 | this.setNextReview(nextReview); 24 | this.stage = 0; 25 | } 26 | 27 | 28 | public int getId() { 29 | return id; 30 | } 31 | 32 | public void setId(int id) { 33 | this.id = id; 34 | } 35 | 36 | public Word getWord() { 37 | return word; 38 | } 39 | 40 | public void setWord(Word word) { 41 | this.word = word; 42 | } 43 | 44 | public long getNextReview() { 45 | return nextReview; 46 | } 47 | 48 | public void setNextReview(long nextReview) { 49 | this.nextReview = nextReview; 50 | } 51 | 52 | public int getStage() { 53 | return stage; 54 | } 55 | 56 | public void setStage(int stage) { 57 | this.stage = stage; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | import android.support.v7.app.ActionBarActivity; 4 | import android.os.Bundle; 5 | import android.util.Log; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | 9 | import java.io.IOException; 10 | 11 | 12 | public class MainActivity extends ActionBarActivity { 13 | private static final String TAG = "MAIN_ACTIVITY"; 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_main); 18 | 19 | SqliteHelper dbs = SqliteHelper.createInstance(this); 20 | RealmHelper dbr = RealmHelper.createInstance(this); 21 | SqliteToRealm dbsr = SqliteToRealm.createInstance(this); 22 | 23 | try { 24 | dbs.createDataBase(); 25 | // dbsr.SqliteToRealm(); 26 | 27 | Log.d(TAG, dbr.getWord(76).getSynonyms().get(0).getText()); 28 | } catch (IOException e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | 33 | @Override 34 | public boolean onCreateOptionsMenu(Menu menu) { 35 | // Inflate the menu; this adds items to the action bar if it is present. 36 | getMenuInflater().inflate(R.menu.menu_main, menu); 37 | return true; 38 | } 39 | 40 | @Override 41 | public boolean onOptionsItemSelected(MenuItem item) { 42 | // Handle action bar item clicks here. The action bar will 43 | // automatically handle clicks on the Home/Up button, so long 44 | // as you specify a parent activity in AndroidManifest.xml. 45 | int id = item.getItemId(); 46 | 47 | //noinspection SimplifiableIfStatement 48 | if (id == R.id.action_settings) { 49 | return true; 50 | } 51 | 52 | return super.onOptionsItemSelected(item); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/RealmHelper.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | import android.content.Context; 5 | import android.util.Log; 6 | 7 | import java.util.List; 8 | 9 | import io.realm.Realm; 10 | import io.realm.RealmList; 11 | 12 | public class RealmHelper { 13 | private static Context mContext; 14 | private static RealmHelper mInstance; 15 | private RealmList words; 16 | public static RealmHelper createInstance(Context context){ 17 | return mInstance = new RealmHelper(context); 18 | } 19 | public static RealmHelper getIntance(){ 20 | return mInstance; 21 | } 22 | private RealmHelper(Context context){ 23 | mContext = context; 24 | } 25 | 26 | public void loadWords(List allWords){ 27 | // this.words = 28 | Log.d("8888888888",mContext.toString()); 29 | Realm.deleteRealmFile(mContext); 30 | Realm realm = Realm.getInstance(mContext); 31 | // words = new RealmList<>(); 32 | realm.beginTransaction(); 33 | // for (Word word : allWords){ 34 | // words.add(realm.copyToRealm()) 35 | // } 36 | realm.copyToRealm(allWords); 37 | realm.commitTransaction(); 38 | 39 | } 40 | public void addSynonymToWords(List synonyms){ 41 | Realm realm = Realm.getInstance(mContext); 42 | realm.beginTransaction(); 43 | for(IntPair pair : synonyms){ 44 | if(pair.getFirstVal() > 5000 || pair.getSocondVal() > 5000) 45 | continue; 46 | RealmList wordSynonyms = realm.where(Word.class).equalTo("id",pair.getFirstVal()).findFirst().getSynonyms(); 47 | Log.d("8888888888888",pair.toString()); 48 | wordSynonyms.add(realm.where(Word.class).equalTo("id",pair.getSocondVal()).findFirst()); 49 | } 50 | realm.commitTransaction(); 51 | } 52 | 53 | public Word getWord(int id){ 54 | Realm realm = Realm.getInstance(mContext); 55 | return realm.where(Word.class).equalTo("id",id).findFirst(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/SqliteToRealm.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | import android.content.Context; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import io.realm.RealmList; 9 | 10 | public class SqliteToRealm { 11 | private static SqliteToRealm mInstance; 12 | private static Context mContext; 13 | 14 | public static SqliteToRealm createInstance(Context context){ 15 | return mInstance = new SqliteToRealm(context); 16 | } 17 | public static SqliteToRealm getInstance() { 18 | return mInstance; 19 | } 20 | 21 | private SqliteToRealm(Context context) { 22 | this.mContext =context; 23 | } 24 | 25 | public List getAllRawWords(){ 26 | List> records = SqliteHelper.getInstance().getRecords("word"); 27 | List words = new ArrayList<>(); 28 | for(List record : records){ 29 | Word word = new Word(); 30 | word.setId(Integer.parseInt(record.get(0))); 31 | word.setFavorite(false); 32 | word.setText(record.get(1)); 33 | word.setDefinition(record.get(2)); 34 | // word.setImage(record.get(2)); 35 | word.setLevel(Integer.parseInt(record.get(5))); 36 | words.add(word); 37 | } 38 | return words; 39 | } 40 | 41 | public void pushSynonymsToWords(){ 42 | SqliteHelper dbs = SqliteHelper.getInstance(); 43 | RealmHelper dbr = RealmHelper.getIntance(); 44 | List rawWords = getAllRawWords(); 45 | List> records = dbs.getRecords("synonym"); 46 | List synonyms = new ArrayList<>(); 47 | for(List record : records){ 48 | if(null == record.get(0) || null == record.get(1)) 49 | continue; 50 | IntPair pair = new IntPair(Integer.parseInt(record.get(0)),Integer.parseInt(record.get(1))); 51 | synonyms.add(pair); 52 | } 53 | dbr.addSynonymToWords(synonyms); 54 | } 55 | 56 | public void SqliteToRealm(){ 57 | // SqliteHelper dbs = SqliteHelper.getInstance(); 58 | RealmHelper dbr = RealmHelper.getIntance(); 59 | List words = getAllRawWords(); 60 | dbr.loadWords(words); 61 | pushSynonymsToWords(); 62 | 63 | } 64 | 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/Course.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | import io.realm.RealmList; 4 | import io.realm.RealmObject; 5 | import io.realm.annotations.PrimaryKey; 6 | 7 | public class Course extends RealmObject{ 8 | 9 | @PrimaryKey 10 | private int id; 11 | 12 | private String name; 13 | 14 | private int numStageRequired; 15 | 16 | private int numNewWordPerDay; 17 | 18 | private int CourseType; 19 | 20 | private RealmList reviewableWords; 21 | 22 | private RealmList needMoreReview; 23 | 24 | public Course(){ } 25 | 26 | public Course(int numNewWordPerDay, int numWordLimitPerDay){ 27 | this.numNewWordPerDay = numNewWordPerDay; 28 | this.numStageRequired = 5; 29 | } 30 | 31 | public Course(int numNewWordPerDay, int numWordLimitPerDay, int numStageRequired){ 32 | this.numNewWordPerDay = numNewWordPerDay; 33 | this.numStageRequired = numStageRequired; 34 | } 35 | 36 | 37 | public int getId() { 38 | return id; 39 | } 40 | 41 | public void setId(int id) { 42 | this.id = id; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | 49 | public void setName(String name) { 50 | this.name = name; 51 | } 52 | 53 | public int getNumStageRequired() { 54 | return numStageRequired; 55 | } 56 | 57 | public void setNumStageRequired(int numStageRequired) { 58 | this.numStageRequired = numStageRequired; 59 | } 60 | 61 | public int getNumNewWordPerDay() { 62 | return numNewWordPerDay; 63 | } 64 | 65 | public void setNumNewWordPerDay(int numNewWordPerDay) { 66 | this.numNewWordPerDay = numNewWordPerDay; 67 | } 68 | 69 | public RealmList getReviewableWords() { 70 | return reviewableWords; 71 | } 72 | 73 | public void setReviewableWords(RealmList reviewableWords) { 74 | this.reviewableWords = reviewableWords; 75 | } 76 | 77 | public RealmList getNeedMoreReview() { 78 | return needMoreReview; 79 | } 80 | 81 | public void setNeedMoreReview(RealmList needMoreReview) { 82 | this.needMoreReview = needMoreReview; 83 | } 84 | 85 | public int getCourseType() { 86 | return CourseType; 87 | } 88 | 89 | public void setCourseType(int courseType) { 90 | CourseType = courseType; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/Word.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | 4 | import io.realm.RealmList; 5 | import io.realm.RealmObject; 6 | import io.realm.annotations.PrimaryKey; 7 | 8 | public class Word extends RealmObject { 9 | 10 | @PrimaryKey 11 | private int id; 12 | 13 | private String text; 14 | 15 | private String definition; 16 | 17 | private RealmList synonyms; 18 | 19 | private RealmList antonyms; 20 | 21 | private RealmList sentences; 22 | 23 | private String image; 24 | 25 | private int level; 26 | 27 | private boolean isFavorite; 28 | 29 | public Word() { 30 | } 31 | 32 | public Word(String word) { 33 | this.text = word; 34 | } 35 | 36 | public int getId() { 37 | return id; 38 | } 39 | 40 | public void setId(int id) { 41 | this.id = id; 42 | } 43 | 44 | public String getText() { 45 | return text; 46 | } 47 | 48 | public void setText(String text) { 49 | this.text = text; 50 | } 51 | 52 | public RealmList getSynonyms() { 53 | return synonyms; 54 | } 55 | 56 | public void setSynonyms(RealmList synonyms) { 57 | this.synonyms = synonyms; 58 | } 59 | 60 | public RealmList getAntonyms() { 61 | return antonyms; 62 | } 63 | 64 | public void setAntonyms(RealmList antonyms) { 65 | this.antonyms = antonyms; 66 | } 67 | 68 | public RealmList getSentences() { 69 | return sentences; 70 | } 71 | 72 | public void setSentences(RealmList sentences) { 73 | this.sentences = sentences; 74 | } 75 | 76 | public String getImage() { 77 | return image; 78 | } 79 | 80 | public void setImage(String image) { 81 | this.image = image; 82 | } 83 | 84 | public boolean isFavorite() { 85 | return isFavorite; 86 | } 87 | 88 | public void setFavorite(boolean isFavorite) { 89 | this.isFavorite = isFavorite; 90 | } 91 | 92 | public int getLevel() { 93 | return level; 94 | } 95 | 96 | public void setLevel(int level) { 97 | this.level = level; 98 | } 99 | 100 | public String getDefinition() { 101 | return definition; 102 | } 103 | 104 | public void setDefinition(String definition) { 105 | this.definition = definition; 106 | } 107 | 108 | public void setIsFavorite(boolean isFavorite) { 109 | this.isFavorite = isFavorite; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /app/src/main/java/com/jixa/converter/SqliteHelper.java: -------------------------------------------------------------------------------- 1 | package com.jixa.converter; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.OutputStream; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import android.content.Context; 12 | import android.database.Cursor; 13 | import android.database.SQLException; 14 | import android.database.sqlite.SQLiteDatabase; 15 | import android.database.sqlite.SQLiteOpenHelper; 16 | import android.util.Log; 17 | 18 | import io.realm.Realm; 19 | import io.realm.RealmResults; 20 | 21 | public class SqliteHelper extends SQLiteOpenHelper 22 | { 23 | private static String TAG = "DataBaseHelper"; 24 | private static String DB_PATH = ""; 25 | private static String DB_NAME ="all.db"; 26 | private SQLiteDatabase mDataBase; 27 | private static Context mContext; 28 | private static SqliteHelper mInstance; 29 | 30 | public static SqliteHelper createInstance(Context context){ 31 | return mInstance = new SqliteHelper(context); 32 | } 33 | public static SqliteHelper getInstance(){ 34 | return mInstance; 35 | } 36 | 37 | private SqliteHelper(Context context) 38 | { 39 | super(context, DB_NAME, null, 1);// 1? its Database Version 40 | mContext = context; 41 | if(android.os.Build.VERSION.SDK_INT >= 17){ 42 | DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; 43 | } 44 | else 45 | { 46 | DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; 47 | } 48 | this.mContext = context; 49 | } 50 | 51 | public void createDataBase() throws IOException 52 | { 53 | 54 | boolean mDataBaseExist = checkDataBase(); 55 | if(!mDataBaseExist) 56 | { 57 | this.getReadableDatabase(); 58 | this.close(); 59 | try 60 | { 61 | copyDataBase(); 62 | Log.e(TAG, "createDatabase database created"); 63 | } 64 | catch (IOException mIOException) 65 | { 66 | throw new Error("ErrorCopyingDataBase"); 67 | } 68 | } 69 | } 70 | private boolean checkDataBase() 71 | { 72 | // return false; 73 | File dbFile = new File(DB_PATH + DB_NAME); 74 | //Log.v("dbFile", dbFile + " "+ dbFile.exists()); 75 | return dbFile.exists(); 76 | } 77 | 78 | private void copyDataBase() throws IOException 79 | { 80 | InputStream mInput = mContext.getAssets().open(DB_NAME); 81 | String outFileName = DB_PATH + DB_NAME; 82 | OutputStream mOutput = new FileOutputStream(outFileName); 83 | byte[] mBuffer = new byte[1024]; 84 | int mLength; 85 | while ((mLength = mInput.read(mBuffer))>0) 86 | { 87 | mOutput.write(mBuffer, 0, mLength); 88 | } 89 | mOutput.flush(); 90 | mOutput.close(); 91 | mInput.close(); 92 | } 93 | 94 | //Open the database, so we can query it 95 | public boolean openDataBase() throws SQLException 96 | { 97 | String mPath = DB_PATH + DB_NAME; 98 | //Log.v("mPath", mPath); 99 | mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.CREATE_IF_NECESSARY); 100 | //mDataBase = SQLiteDatabase.openDatabase(mPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS); 101 | 102 | return mDataBase != null; 103 | } 104 | 105 | public List> getRecords(String tableName){ 106 | SQLiteDatabase reader = getReadableDatabase(); 107 | Cursor cursor = reader.rawQuery("SELECT * FROM " + tableName,null); 108 | cursor.moveToFirst(); 109 | List> records = new ArrayList<>(); 110 | int t =0; 111 | do { 112 | Log.d("888888888", String.valueOf( t++)); 113 | if(t>5000) 114 | break; 115 | List record = new ArrayList<>(); 116 | for(int i =0 ; i readWords(){ 136 | // Realm realm = Realm.getInstance(mContext); 137 | // Cursor cursor = reader.rawQuery("SELECT * FROM TOFEL",null); 138 | // cursor.moveToFirst(); 139 | // realm.beginTransaction(); 140 | // do { 141 | // TestWord word = realm.createObject(TestWord.class); 142 | // word.setId(Integer.parseInt(cursor.getString(0))); 143 | // word.setWord(cursor.getString(1)); 144 | //// Log.d(TAG,cursor.getString(0)); 145 | // 146 | // }while(cursor.moveToNext()); 147 | // realm.commitTransaction(); 148 | // return null; 149 | // } 150 | // 151 | // public RealmResults getWord(int id){ 152 | // Realm realm = Realm.getInstance(mContext); 153 | // return realm.where(TestWord.class).equalTo("id",id).findAll(); 154 | // } 155 | 156 | @Override 157 | public synchronized void close() 158 | { 159 | if(mDataBase != null) 160 | mDataBase.close(); 161 | super.close(); 162 | } 163 | 164 | @Override 165 | public void onCreate(SQLiteDatabase sqLiteDatabase) { 166 | 167 | } 168 | 169 | @Override 170 | public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { 171 | 172 | } 173 | 174 | } --------------------------------------------------------------------------------