Info Android Studio and SQLite where clausole -
how add lang = xxx clause on code? have modified sqlite database , structure of same if there no language should call en language in clause. it's same function mysql php or changes?
variablelang = locale.getdefault().getlanguage();
select ..... lang = variablelang
wsdatabase.java
public class wsdatabase extends sqliteassethelper { private static final string database_name = "db.sqlite"; private static final int database_version = 1; private sqlitedatabase database; public wsdatabase(context context) { super(context, database_name, null, database_version); setforcedupgrade(); } public void open() { database = getreadabledatabase(); } public cursor getlevels() { return database.query(constants.level_table_name, null, null, null, null, null, null); } public cursor getwordsbylevel(int level) { return database.query(constants.grid_data_table_name, null, constants.grid_data_table_level_id + " = ?", new string[]{integer.tostring(level)}, null, null, constants.grid_data_table_level_order); } public boolean islevellocked(int level) { cursor cursor = database.query(constants.level_table_name, null, constants.level_table_id + " = ?", new string[]{integer.tostring(level)}, null, null, null); boolean status = cursor != null && cursor.movetofirst() && cursor.getint(cursor.getcolumnindex(constants.level_table_locked)) == 0; if (cursor != null) cursor.close(); return status; } public cursor getnextquestion(int level, int questionid) { return database.query(constants.grid_data_table_name, null, constants.grid_data_table_level_id + " = ? , " + constants.grid_data_table_id + " > ?", new string[]{integer.tostring(level), integer.tostring(questionid)}, null, null, constants.grid_data_table_level_order); } public void unlocklevel(int level) { database.execsql("update " + constants.level_table_name + " set " + constants.level_table_locked + "= 1 " + constants.level_table_id + "= " + level); cursor cursor = database.query(constants.grid_data_table_name, new string[]{"min(" + constants.grid_data_table_id + ")"}, constants.grid_data_table_level_id + " = ?", new string[]{integer.tostring(level)}, null, null, null); if (cursor != null && cursor.getcount() > 0) { cursor.movetofirst(); setsolvestatus(cursor.getint(0)); cursor.close(); } } public void setsolvestatus(int questionid) { database.execsql("update " + constants.grid_data_table_name + " set " + constants.grid_data_table_solved + "= 1 " + constants.grid_data_table_id + "= " + questionid); } public cursor getcompletiontime(int questionid) { return database.query(constants.grid_data_table_name, new string[]{constants.grid_data_table_solved_time}, constants.grid_data_table_id + " = ?", new string[]{integer.tostring(questionid)}, null, null, null); } public boolean setcompletiontime(int questionid, long timeinmillisec, int score) { cursor cursor = getcompletiontime(questionid); if (cursor != null && cursor.getcount() > 0) { cursor.movetofirst(); int t = cursor.getint(0); if (t == 0) { database.execsql("update " + constants.grid_data_table_name + " set " + constants.grid_data_table_solved_time + "= " + timeinmillisec + " " + constants.grid_data_table_id + "= " + questionid); database.execsql("update " + constants.grid_data_table_name + " set " + constants.grid_data_table_score + "= " + score + " " + constants.grid_data_table_id + "= " + questionid); return true; } cursor.close(); } return false; }
f.java
@efragment(r.layout.fragment_level) public class firstlevelfragment extends basefragment implements loadermanager.loadercallbacks<cursor>, adapterview.onitemclicklistener { @viewbyid listview listview; @viewbyid adview adview; firstleveladapter firstleveladapter; private wsdatabase wsd; private explode explode; @afterviews void init() { if (mainactivitycommunication != null) mainactivitycommunication.settitle(getstring(r.string.app_title)); customadviewbuilder.initiatead(adview); //opening database wsd = new wsdatabase(getactivity()); wsd.open(); //list adapter initialisation firstleveladapter = new firstleveladapter(getactivity(), null); alphainanimationadapter animadapter = new alphainanimationadapter(firstleveladapter); animadapter.setabslistview(listview); assert animadapter.getviewanimator() != null; listview.setadapter(animadapter); listview.setonitemclicklistener(this); if (build.version.sdk_int >= build.version_codes.lollipop) { explode = new explode(); explode.setduration(400); } //initialise cursor loader getloadermanager().initloader(0, null, this); } @override public loader<cursor> oncreateloader(int id, bundle args) { return new cursorloader(getactivity()) { @override public cursor loadinbackground() { return wsd.getlevels(); } }; } @override public void onloadfinished(loader<cursor> loader, cursor data) { firstleveladapter.swapcursor(data); firstleveladapter.notifydatasetchanged(); } @override public void onloaderreset(loader<cursor> loader) { } @override public void onresume() { super.onresume(); getloadermanager().restartloader(0, null, this); } @override public void ondestroy() { super.ondestroy(); if (wsd != null) wsd.close(); } @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { cursor c = firstleveladapter.getcursor(); c.movetoposition(position); if (c.getint(c.getcolumnindex(constants.level_table_locked)) == 1) { fragment fragment = secondlevelfragment_.builder().color(firstleveladapter.getcolorcode(position)).levelid(c.getint(c.getcolumnindex(constants.level_table_id))).levelname(c.getstring(c.getcolumnindex(constants.level_table_level_name))).levellang(c.getstring(c.getcolumnindex(constants.level_table_lang))).build(); if (build.version.sdk_int >= build.version_codes.lollipop) { fragment.setentertransition(explode); } getfragmentmanager().begintransaction().replace(r.id.fragmentholder, fragment).addtobackstack(null).commit(); } }
sl.java
@efragment(r.layout.fragment_level) public class secondlevelfragment extends basefragment implements loadermanager.loadercallbacks<cursor>, adapterview.onitemclicklistener { @viewbyid listview listview; @viewbyid adview adview; @fragmentarg int levelid; @fragmentarg string levelname; @fragmentarg string levellang; @fragmentarg int color; secondleveladapter secondleveladapter; private wsdatabase wsd; private explode explode; @afterviews void init() { int color = contextcompat.getcolor(getactivity(), this.color); customadviewbuilder.initiatead(adview); if(mainactivitycommunication!=null) mainactivitycommunication.settitle(levelname, color); //opening database wsd = new wsdatabase(getactivity()); wsd.open(); //list adapter initialisation secondleveladapter = new secondleveladapter(getactivity(), null, color); alphainanimationadapter animadapter = new alphainanimationadapter(secondleveladapter); animadapter.setabslistview(listview); assert animadapter.getviewanimator() != null; listview.setadapter(animadapter); listview.setonitemclicklistener(this); if (build.version.sdk_int >= build.version_codes.lollipop) { explode = new explode(); explode.setduration(400); } //initialise cursor loader getloadermanager().initloader(0, null, this); } @override public loader<cursor> oncreateloader(int id, bundle args) { return new cursorloader(getactivity()) { @override public cursor loadinbackground() { return wsd.getwordsbylevel(levelid); } }; } @override public void ondestroy() { super.ondestroy(); if (wsd != null) wsd.close(); } @override public void onresume() { super.onresume(); getloadermanager().restartloader(0, null, this); } @override public void onloadfinished(loader<cursor> loader, cursor data) { secondleveladapter.swapcursor(data); secondleveladapter.notifydatasetchanged(); } @override public void onloaderreset(loader<cursor> loader) { } @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { cursor c = secondleveladapter.getcursor(); c.movetoposition(position); if (c.getint(c.getcolumnindex(constants.grid_data_table_solved)) == 1) { fragment fragment = gamefragement_.builder().color(color).levelid(c.getint(c.getcolumnindex(constants.grid_data_table_level_id))).questionid(c.getint(c.getcolumnindex(constants.grid_data_table_id))).order(c.getstring(c.getcolumnindex(constants.grid_data_table_order))).wordstring(c.getstring(c.getcolumnindex(constants.grid_data_table_words))).build(); if (build.version.sdk_int >= build.version_codes.lollipop) { fragment.setentertransition(explode); } getfragmentmanager().begintransaction().replace(r.id.fragmentholder, fragment).addtobackstack(null).commit(); } }
constants.java
public class constants { public final static string level_table_name = "level_name"; public final static string level_table_id = "_id"; public final static string level_table_level_name = "name"; public final static string level_table_locked = "locked"; public final static string level_table_lang = "lang"; public final static string grid_data_table_name = "grid_data"; public final static string grid_data_table_id = "_id"; public final static string grid_data_table_level_id = "level_id"; public final static string grid_data_table_words = "words"; public final static string grid_data_table_order = "order"; public final static string grid_data_table_level_order = "level_order"; public final static string grid_data_table_solved = "solved"; public final static string grid_data_table_solved_time = "solved_time"; public final static string grid_data_table_score = "score"; public final static string grid_data_table_lang = "lang";
}
Comments
Post a Comment