Skip to content

Commit

Permalink
NClientV2 1.5.9
Browse files Browse the repository at this point in the history
Upgraded DB
Favorite added to database management
  • Loading branch information
Dar9586 committed Oct 23, 2018
1 parent 9b95f0c commit 6a1054e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.dar.nclientv2"
minSdkVersion 21
targetSdkVersion 28
versionCode 158
versionName "1.5.8"
versionCode 159
versionName "1.5.9"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}
Expand Down
35 changes: 21 additions & 14 deletions app/src/main/java/com/dar/nclientv2/adapters/FavoriteAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public class FavoriteAdapter extends RecyclerView.Adapter<GenericAdapter.ViewHol
public FavoriteAdapter(FavoriteActivity activity,boolean online) {
this.online=online;
this.activity=activity;
this.lastQuery=null;
this.lastQuery="";
new FavoriteLoader(this,online).start();
}
public void endLoader(){
firstIsRunning=false;
activity.runOnUiThread(()->activity.getRefresher().setRefreshing(false));
forceReload();
}
@NonNull
@Override
Expand Down Expand Up @@ -90,47 +90,58 @@ public Filter getFilter(){
return new Filter(){
@Override
protected FilterResults performFiltering(CharSequence constraint){
constraint=constraint.toString().toLowerCase(Locale.US);
if(firstIsRunning||(!force&&lastQuery.equals(constraint)))return null;
Log.d(Global.LOGTAG,"FILTERING");
activity.runOnUiThread(()->activity.getRefresher().setRefreshing(true));
setRefresh(true);
FilterResults results=new FilterResults();
lastQuery=constraint;
lastQuery=constraint.toString();
force=false;
List<Gallery>gal=new ArrayList<>();
for(Gallery g:galleries){
if(lastQuery==null||g.getTitle().contains(lastQuery))gal.add(g);
if(g.getTitle().toLowerCase(Locale.US).contains(lastQuery))gal.add(g);
}
results.count=gal.size();
results.values=gal;
Log.d(Global.LOGTAG,"FILTERING3");
Log.e(Global.LOGTAG,results.count+";"+results.values);
setRefresh(false);
return results;
}

@Override
protected void publishResults(CharSequence constraint, FilterResults results){
if(results.count==-1||results.values==null)return;
if(results==null)return;
setRefresh(true);
Log.d(Global.LOGTAG,"After called2");
final int oldSize=getItemCount(),newSize=results.count;
filterGalleries=(List<Gallery>)results.values;
activity.runOnUiThread(()->{
if(oldSize>newSize)notifyItemRangeRemoved(newSize,oldSize-newSize);
else notifyItemRangeInserted(oldSize,newSize-oldSize);
notifyItemRangeChanged(0,Math.min(newSize,oldSize));
if(!firstIsRunning)activity.getRefresher().setRefreshing(false);
});

setRefresh(false);
}
};
}
public void addItem(Gallery gallery){
galleries.add(gallery);
if(lastQuery==null||gallery.getTitle().contains(lastQuery)){
if(gallery.getTitle().contains(lastQuery)){
filterGalleries.add(gallery);
activity.runOnUiThread(()->notifyItemInserted(filterGalleries.size()));
}

}
public void forceReload(){
if(firstIsRunning)return;
Log.d(Global.LOGTAG,"FORCING",new Exception("STACK TRACE"));
force=true;
getFilter().filter(lastQuery);

}
public void setRefresh(boolean refresh){
Thread.dumpStack();
activity.runOnUiThread(()->activity.getRefresher().setRefreshing(refresh));
}
public void clearGalleries(){
Queries.GalleryTable.removeAllFavorite(Database.getDatabase(),online);
Expand All @@ -142,8 +153,4 @@ public void clearGalleries(){
public void reloadOnline(){
new DownloadFavorite(this).start();
}

public FavoriteActivity getActivity() {
return activity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void onCreate(SQLiteDatabase db){
passOldFavorite(db);
passOldFilters(db);
passOldOnlineFavorite(db);
Queries.DebugDatabase.dumpDatabase(db);
//Queries.DebugDatabase.dumpDatabase(db);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public static Gallery[] getAllFavorite(SQLiteDatabase db,CharSequence query,bool
int i=0;
if(cursor.moveToFirst()){
do{
DatabaseUtils.dumpCurrentRow(cursor);
Gallery g=cursorToGallery(db,cursor);
galleries[i++]=g;
}while(cursor.moveToNext());
Expand Down Expand Up @@ -233,7 +232,6 @@ public static void removeAllFavorite(SQLiteDatabase db, boolean online){
}

public static Gallery cursorToGallery(SQLiteDatabase db,Cursor cursor) throws IOException{
DatabaseUtils.dumpCurrentRow(cursor);
return new Gallery(cursor,BridgeTable.getTagsForGallery(db,cursor.getInt(getColumnFromName(cursor,IDGALLERY))));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void run() {
pauseMainLoop();
}while (++page<=Login.getUser().getTotalPages());
//end search
adapter.getActivity().runOnUiThread(() -> adapter.getActivity().getRefresher().setRefreshing(false));
adapter.setRefresh(false);
Log.e(Global.LOGTAG,"Total: "+adapter.getItemCount());
//Queries.DebugDatabase.dumpDatabase(Database.getDatabase());
}
Expand Down

0 comments on commit 6a1054e

Please sign in to comment.