Skip to content

Commit

Permalink
NClientV2 1.8.1
Browse files Browse the repository at this point in the history
+ Show popular tags in advanced search
  • Loading branch information
Dar9586 committed Mar 4, 2019
1 parent 428bc68 commit 440053b
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 16 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 14
targetSdkVersion 28
versionCode 180
versionName "1.8.0"
versionCode 181
versionName "1.8.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/dar/nclientv2/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ protected void onCreate(Bundle savedInstanceState) {
Global.initInfiniteScroll(this);
com.dar.nclientv2.settings.Login.initUseAccountTag(this);
setContentView(R.layout.activity_main);
Intent i=new Intent(this,ScrapeTags.class);
startService(i);
//getSharedPreferences("Settings",0).edit().remove("first_run").apply();

final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(true);
Expand Down Expand Up @@ -163,6 +161,8 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy){
} else new Inspector(this,1,"",ApiRequestType.BYALL);
if(firstTime){
if(Global.shouldCheckForUpdates(this))new VersionChecker(this,true);
Intent i=new Intent(this,ScrapeTags.class);
startService(i);
firstTime=false;
}
}
Expand Down
28 changes: 27 additions & 1 deletion app/src/main/java/com/dar/nclientv2/SearchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.view.inputmethod.EditorInfoCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand All @@ -15,6 +16,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
Expand Down Expand Up @@ -128,7 +130,10 @@ public boolean onQueryTextChange(String newText) {

}
private void populateGroup(){
for(Tag t:Queries.TagTable.getAllFiltered(Database.getDatabase()))addTag(t);
for(TagType type:new TagType[]{TagType.TAG,TagType.PARODY,TagType.CHARACTER,TagType.ARTIST,TagType.GROUP}) {
for (Tag t : Queries.TagTable.getTopTags(Database.getDatabase(),type,Global.getFavoriteLimit(this)))addTopTag(t);
}
for(Tag t:Queries.TagTable.getAllFiltered(Database.getDatabase()))if(!tagAlreadyExist(t.getName()))addTag(t);
for(Tag t:Queries.TagTable.getTrueAllType(Database.getDatabase(),TagType.CATEGORY))addSpecialTag(t);
for(Tag t:Queries.TagTable.getTrueAllType(Database.getDatabase(),TagType.LANGUAGE)){
if(Global.getOnlyLanguage()== Language.UNKNOWN)t.setStatus(TagStatus.AVOIDED);
Expand All @@ -153,12 +158,31 @@ private void populateGroup(){
Chip c=(Chip)getLayoutInflater().inflate(R.layout.chip_layout,cg,false);
c.setCloseIconVisible(false);
c.setChipIconResource(R.drawable.ic_add);
DrawableCompat.setTint(c.getChipIcon(), Color.BLACK);
c.setText(getString(R.string.add));
c.setOnClickListener(v -> loadTag(type));
addChip[type.ordinal()]=c;
cg.addView(c);
}
}
private boolean tagAlreadyExist(String s){
for(ChipTag t:tags){
if(t.getTag().getName().equals(s))return true;
}
return false;
}
private void addTopTag(Tag t) {
ChipGroup cg=getGroup(t.getType());
ChipTag c=(ChipTag)getLayoutInflater().inflate(R.layout.chip_layout_entry,cg,false);
c.setTag(t);
c.setCloseIconVisible(false);
c.setOnClickListener(v -> {
c.changeStatus(t.getStatus()== TagStatus.ACCEPTED?TagStatus.AVOIDED:t.getStatus()==TagStatus.AVOIDED?TagStatus.DEFAULT:TagStatus.ACCEPTED);
advanced=true;
});
cg.addView(c);
tags.add(c);
}

private void addSpecialTag(Tag t) {
ChipGroup cg=getGroup(t.getType());
Expand Down Expand Up @@ -216,6 +240,7 @@ private ChipGroup getGroup(TagType type){
private void addDialog(){
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setView(autoComplete);
autoComplete.setText("");
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
createChip();
});
Expand All @@ -232,6 +257,7 @@ private void addDialog(){

private void createChip() {
Tag t=new Tag(autoComplete.getText().toString().toLowerCase(Locale.US),0,0,editTag,TagStatus.ACCEPTED);
if(tagAlreadyExist(t.getName()))return;
getGroup(editTag).removeView(addChip[editTag.ordinal()]);
addTag(t);
getGroup(editTag).addView(addChip[editTag.ordinal()]);
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/dar/nclientv2/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,25 @@ public void positive(int actual) {
);
return true;
});
findPreference(getString(R.string.key_favorite_limit)).setOnPreferenceClickListener(preference -> {
DefaultDialogs.pageChangerDialog(
new DefaultDialogs.Builder(getActivity())
.setDrawable(R.drawable.ic_hashtag)
.setTitle(R.string.favorite_count)
.setMax(20)
.setActual(Global.getFavoriteLimit(getActivity()))
.setMin(0)
.setDialogs(new DefaultDialogs.DialogResults() {
@Override
public void positive(int actual) {
Global.updateFavoriteLimit(getActivity(),actual);
}

@Override public void negative() {}
})
);
return true;
});
}

private void removePic(){
Expand Down
19 changes: 11 additions & 8 deletions app/src/main/java/com/dar/nclientv2/api/local/LocalGallery.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ public LocalGallery(File file, int id){
//Inizio ricerca pagine
File[] files=file.listFiles((dir, name) -> name.endsWith(".jpg")&&name.length()==7);
//trova la pagina col numero piu grande
if(files.length<1) Log.e(Global.LOGTAG,"FILE INESISTENTI");
for(File f:files){
try {
int x = Integer.parseInt(f.getName().substring(0, 3));
if(x>max)max=x;
if(x<min)min=x;
}catch (NumberFormatException e){Log.e(Global.LOGTAG,e.getLocalizedMessage(),e);}
if(files!=null) {
if (files.length < 1) Log.e(Global.LOGTAG, "FILE INESISTENTI");
for (File f : files) {
try {
int x = Integer.parseInt(f.getName().substring(0, 3));
if (x > max) max = x;
if (x < min) min = x;
} catch (NumberFormatException e) {
Log.e(Global.LOGTAG, e.getLocalizedMessage(), e);
}
}
}

this.max=max;
this.min=min;
valid=max<1000&&min>0&&id!=-1;
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/dar/nclientv2/async/ScrapeTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

import androidx.annotation.Nullable;
import okhttp3.Request;
import okhttp3.Response;

public class ScrapeTags extends IntentService {
/*It is updated once a month*/
private static final String URL="https://violable-hats.000webhostapp.com/tags.json";

private static final String ALTERNATIVE_URL="https://raw.githubusercontent.com/Dar9586/NClientV2/master/data/tags.json";
//check every 30day
private static final long DIFFERENCE_TIME=30L*24*60*60;
public ScrapeTags() {
Expand All @@ -31,7 +35,10 @@ public ScrapeTags() {
protected void onHandleIntent(@Nullable Intent intent) {
try {
if(new Date().getTime()-getApplicationContext().getSharedPreferences("Settings",0).getLong("lastSync",new Date().getTime())<DIFFERENCE_TIME)return;
JsonReader reader=new JsonReader(Global.client.newCall(new Request.Builder().url(URL).build()).execute().body().charStream());
Response x=Global.client.newCall(new Request.Builder().url(URL).build()).execute();
if(x.code()!=200)x=Global.client.newCall(new Request.Builder().url(ALTERNATIVE_URL).build()).execute();
if(x.code()!=200)return;
JsonReader reader=new JsonReader(x.body().charStream());
reader.beginArray();
int id=reader.nextInt();
String name=reader.nextString();
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/dar/nclientv2/async/database/Queries.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -359,7 +360,20 @@ public static void resetAllStatus(SQLiteDatabase db){
values.put(STATUS,TagStatus.DEFAULT.ordinal());
db.updateWithOnConflict(TABLE_NAME,values,null,null,SQLiteDatabase.CONFLICT_IGNORE);
}
public static Tag[] getTopTags(SQLiteDatabase db,TagType type,int count){
String query="SELECT * FROM "+TABLE_NAME+" WHERE "+TYPE+"=? ORDER BY "+COUNT+" DESC LIMIT ?;";

int i=0;
Cursor cursor=db.rawQuery(query,new String[]{""+type.ordinal(),""+count});
Tag[]tags=new Tag[cursor.getCount()];
if(cursor.moveToFirst()){
do{
tags[i++]=cursorToTag(cursor);
}while(cursor.moveToNext());
}
cursor.close();
return tags;
}
public static TagStatus getStatus(SQLiteDatabase db,Tag tag){
String query="SELECT "+ STATUS +" FROM "+ TABLE_NAME +
" WHERE "+ IDTAG +" =?";
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/dar/nclientv2/loginapi/LoadTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public LoadTags(@Nullable TagsAdapter adapter) {
@Override
public void run() {
super.run();
if(Login.getUser()==null)return;
Log.d(Global.LOGTAG,String.format("Creating blacklist of: https://nhentai.net/users/%s/%s/blacklist",Login.getUser().getId(),Login.getUser().getCodename()));
Global.client.newCall(new Request.Builder().url(String.format(Locale.US,"https://nhentai.net/users/%s/%s/blacklist",Login.getUser().getId(),Login.getUser().getCodename())).build()).enqueue(new Callback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public Builder(Context context) {
dialogs=null;
}

public void setMin(int min){
public Builder setMin(int min){
this.min = min;
return this;
}

public Builder setTitle(int title) {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/dar/nclientv2/settings/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.FragmentActivity;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand All @@ -56,6 +57,12 @@ public static long recursiveSize(File path) {
return size;
}

public static void updateFavoriteLimit(Context context, int limit) {
context.getSharedPreferences("Settings", 0).edit().putInt(context.getString(R.string.key_favorite_limit),limit).apply();
}
public static int getFavoriteLimit(Context context) {
return context.getSharedPreferences("Settings", 0).getInt(context.getString(R.string.key_favorite_limit),10);
}
public enum ThemeScheme{LIGHT,DARK,BLACK}

public static OkHttpClient client=null;
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@
<string name="insert_tag_name">Insert tag name:</string>
<string name="other">other</string>
<string name="cancelling">Cancelling…</string>
<string name="key_favorite_limit">favorite_limit</string>
<string name="favorite_count">Favorite count</string>


<string-array name="theme">
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
android:summaryOn="@string/setting_on_use_account_tag"
android:summaryOff="@string/setting_off_use_account_tag"
android:title="@string/use_account_tag" />
<Preference android:title="@string/favorite_count"
android:key="@string/key_favorite_limit"
android:summary="The number of popular tags shown while in Advanced search"
/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/miscellaneous">
Expand Down
1 change: 1 addition & 0 deletions data/tags.json

Large diffs are not rendered by default.

0 comments on commit 440053b

Please sign in to comment.