Skip to content

Commit

Permalink
NClientV2 2.2.7
Browse files Browse the repository at this point in the history
* Bug fixes
  • Loading branch information
Dar9586 committed May 8, 2020
1 parent 95056ab commit 7df008a
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 28 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 29
versionCode 226
versionName "2.2.6"
versionCode 227
versionName "2.2.7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,12 @@ public GenericGallery getGallery(){

private void loadRelatedLayout(ViewHolder holder){
LogUtility.d("Called RElated");
final RecyclerView recyclerView=(RecyclerView)holder.master;
final RecyclerView recyclerView= holder.master.findViewById(R.id.recycler);
final Gallery gallery=(Gallery)this.gallery;
if(!gallery.isRelatedLoaded()||gallery.getRelated().size()==0){
holder.master.setVisibility(View.GONE);
return;
}else holder.master.setVisibility(View.VISIBLE);
recyclerView.setLayoutManager(new CustomGridLayoutManager(context,1,RecyclerView.HORIZONTAL,false));
if(gallery.isRelatedLoaded()){
ListAdapter adapter=new ListAdapter(context);
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/dar/nclientv2/api/InspectorV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public static InspectorV3 favoriteInspector(Context context,String query, int pa
* @param favorite true if random online favorite, false for general random manga
* */
public static InspectorV3 randomInspector(Context context,InspectorResponse response,boolean favorite){
if(!favorite&&Global.useAlternativeSite())
return InspectorV3.galleryInspector(context,Utility.RANDOM.nextInt(Global.getMaxId()),response);
InspectorV3 inspector=new InspectorV3(context,response);
inspector.requestType=favorite?ApiRequestType.RANDOM_FAVORITE:ApiRequestType.RANDOM;
inspector.createUrl();
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/dar/nclientv2/api/SimpleGallery.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.database.Cursor;
import android.os.Parcel;

import androidx.annotation.NonNull;

import com.dar.nclientv2.api.components.Comment;
import com.dar.nclientv2.api.components.Gallery;
import com.dar.nclientv2.api.components.GenericGallery;
Expand Down Expand Up @@ -102,6 +104,7 @@ public boolean isValid() {
}

@Override
@NonNull
public String getTitle() {
return title;
}
Expand Down
20 changes: 9 additions & 11 deletions app/src/main/java/com/dar/nclientv2/api/components/Gallery.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Gallery(Context context, String json, Elements comments, Elements related
}
@NonNull
public String getPathTitle() {
return getSafeTitle().replace('/', '_').replaceAll("[|\\\\?*<\":>+\\[\\]/']", "_");
return getTitle().replace('/', '_').replaceAll("[|\\\\?*<\":>+\\[\\]/']", "_");
}

private Date uploadDate;
Expand Down Expand Up @@ -94,6 +94,7 @@ public Gallery(Cursor cursor, TagList tags) throws IOException{
complete=true;
//The gallery is added to DB only for local favorite and download
onlineFavorite=false;
LogUtility.d(toString());
}

public boolean isOnlineFavorite() {
Expand Down Expand Up @@ -453,9 +454,15 @@ private void readTitles(JsonReader jr) throws IOException {
public String getFilename(int page){
return String.format(Locale.US,"%03d.%s",page,getPageExtension(page));
}
@NonNull
@Override
public String getTitle() {
return getTitle(Global.getTitleType());
String x=getTitle(Global.getTitleType());
if(x.length()>2)return x;
if((x=getTitle(TitleType.PRETTY)).length()>2)return x;
if((x=getTitle(TitleType.ENGLISH)).length()>2)return x;
if((x=getTitle(TitleType.JAPANESE)).length()>2)return x;
return "Unnamed";
}

public String getTitle(int x){
Expand All @@ -467,15 +474,6 @@ public String getTitle(int x){
public String getTitle(TitleType x){
return getTitle(x.ordinal());
}
@NonNull
public String getSafeTitle(){
String x=getTitle();
if(x.length()>2)return x;
if((x=getTitle(TitleType.ENGLISH)).length()>2)return x;
if((x=getTitle(TitleType.PRETTY)).length()>2)return x;
if((x=getTitle(TitleType.JAPANESE)).length()>2)return x;
return "Unnamed";
}

public Language getLanguage() {
return language;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.os.Parcelable;

import androidx.annotation.NonNull;

import com.dar.nclientv2.components.classes.Size;
import com.dar.nclientv2.utility.Utility;

Expand All @@ -16,6 +18,7 @@ public enum Type{COMPLETE,LOCAL,SIMPLE}
public abstract Type getType();
public abstract int getPageCount();
public abstract boolean isValid();
@NonNull
public abstract String getTitle();
public abstract List<Comment> getComments();
public abstract Size getMaxSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LocalGallery extends GenericGallery{
private final String title;
private final File directory;
private final boolean valid;
private static final Pattern FILE_PATTERN=Pattern.compile("^(\\d{3,9})\\.(gif|png|jpg|jpeg)$",Pattern.CASE_INSENSITIVE);
private static final Pattern FILE_PATTERN=Pattern.compile("^(\\d{3,9})\\.(gif|png|jpg)$",Pattern.CASE_INSENSITIVE);
private Size maxSize=new Size(0,0),minSize=new Size(Integer.MAX_VALUE,Integer.MAX_VALUE);
private File[]retriveValidFiles(){
return directory.listFiles((dir, name) -> FILE_PATTERN.matcher(name).matches());
Expand Down Expand Up @@ -124,6 +124,7 @@ public int getPageCount() {
return max;
}
@Override
@NonNull
public String getTitle() {
return title;
}
Expand All @@ -149,8 +150,6 @@ public static File getPage(File dir,int page){
if(x.exists())return x;
x=new File(dir,pag+"gif");
if(x.exists())return x;
x=new File(dir,pag+"jpeg");
if(x.exists())return x;
return null;
}
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ public static TagList getTagsForGallery(int id){
GalleryBridgeTable.TABLE_NAME,
TagTable.IDTAG,
GalleryBridgeTable.ID_TAG,
GalleryBridgeTable.ID_TAG,
GalleryBridgeTable.ID_GALLERY,
id
);
TagList tagList=new TagList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ private void downloadPage(PageContainer page) {
}
}
private boolean isCorrupted(File file){
String path=file.getAbsolutePath();
if(path.endsWith(".jpg")&&Global.isJPEGCorrupted(path))return true;
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize=256;
Bitmap bitmap=BitmapFactory.decodeFile(file.getAbsolutePath(),options);
Bitmap bitmap=BitmapFactory.decodeFile(path,options);
boolean x= bitmap==null;
if(!x)bitmap.recycle();
bitmap = null;
Expand All @@ -206,25 +208,38 @@ private boolean savePage(PageContainer page) {
Response r = Global.getClient(context).newCall(new Request.Builder().url(page.url).build()).execute();
if (r.code() != 200) {r.close();return false;}
assert r.body() != null;
writeStreamToFile(r.body().byteStream(), filePath);
long expectedSize=Integer.parseInt(r.header("Content-Length","-1"));
long len=r.body().contentLength();
if(len < 0 || expectedSize != len){
r.close();
return false;
}
long written=writeStreamToFile(r.body().byteStream(), filePath);
r.close();
if(written!=len){
filePath.delete();
return false;
}
return true;
}catch (IOException e){
}catch (IOException|NumberFormatException e){
LogUtility.e(e,e);
}
return false;
}

private void writeStreamToFile(InputStream inputStream, File filePath)throws IOException {
private long writeStreamToFile(InputStream inputStream, File filePath)throws IOException {
FileOutputStream outputStream=new FileOutputStream(filePath);
int read;
long totalByte=0;
byte[] bytes = new byte[1024];
while ((read = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
totalByte+=read;
}
outputStream.flush();
outputStream.close();
inputStream.close();
return totalByte;
}

public void initDownload() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/dar/nclientv2/settings/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public static boolean hasStoragePermission(Context context) {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||ContextCompat.checkSelfPermission(context,Manifest.permission.WRITE_EXTERNAL_STORAGE)==PackageManager.PERMISSION_GRANTED;
}

public static boolean isCorrupted(String path){
public static boolean isJPEGCorrupted(String path){
if(!new File(path).exists())return true;
try (RandomAccessFile fh = new RandomAccessFile(path, "r")) {
long length = fh.length();
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/dar/nclientv2/utility/Utility.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

public class Utility {
public static final Random RANDOM=new Random(System.nanoTime());
private static final String BASE_URL="nhentai.net";
private static final String ORIGINAL_URL ="nhentai.net";
private static final String ALTERNATIVE_URL="nhent.ai";
public static String getBaseUrl(){
return "https://"+Utility.getHost()+"/";
}
public static String getHost(){
boolean x=Global.useAlternativeSite();
return x?ALTERNATIVE_URL:BASE_URL;
return x?ALTERNATIVE_URL: ORIGINAL_URL;
}
public static void threadSleep(long millis){
try {
Expand All @@ -49,7 +49,6 @@ public static void tintMenu(Menu menu){
LogUtility.d("Item "+i+": "+item.getItemId()+"; "+item.getTitle());
Global.setTint(item.getIcon());
}
LogUtility.d("\n\n");
}
@Nullable
private static Bitmap drawableToBitmap(Drawable dra){
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/image_void_static.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:backgroundTint="?attr/colorPrimaryVariant"
android:contentDescription="@string/image"
android:scaleType="fitCenter"
app:layout_constraintDimensionRatio="W,16:9"
app:layout_constraintDimensionRatio="3:4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/related_recycler.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/master"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TextView
style="@style/TextAppearance.MaterialComponents.Headline5"
Expand All @@ -11,7 +12,7 @@
android:text="@string/related"
android:layout_marginLeft="8dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/master"
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>

0 comments on commit 7df008a

Please sign in to comment.