Skip to content
This repository has been archived by the owner on Feb 26, 2020. It is now read-only.

fix crush when opened two new chapter screen #68

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
# OpenManga
**! This project is deprecated and moved [Here](https://github.com/nv95/Kotatsu "Kotatsu")**

OpenManga - Powerful manga reader for Android with online catalogues.
[![Build Status](https://travis-ci.org/nv95/OpenManga.svg?branch=master)](https://travis-ci.org/nv95/OpenManga)

## Help
If you can add:
- translation
- source with manga

please add and create pull request

It will be MUCH faster
## OpenManga

OpenManga - Powerful manga reader for Android with online catalogues.
[![Build Status](https://travis-ci.org/nv95/OpenManga.svg?branch=master)](https://travis-ci.org/nv95/OpenManga)

[![Get it on F-Droid](https://cloud.githubusercontent.com/assets/8948226/22860847/7476f5c4-f112-11e6-9031-5ac233d26678.png)](https://f-droid.org/repository/browse/?fdid=org.nv95.openmanga)

Expand Down
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ apply from: "${rootProject.rootDir}/scripts/sign.gradle"
//def versionProps = rootProject.ext.getVersionProps()

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
compileSdkVersion 29
buildToolsVersion "29.0.2"

defaultConfig {
applicationId "org.nv95.openmanga"
minSdkVersion 14
targetSdkVersion 28
versionCode 51333 // version.properties
versionName '4.7.3' // version.properties
targetSdkVersion 29
versionCode 51340 // version.properties
versionName '4.8' // version.properties
buildConfigField "boolean", "SELFUPDATE_ENABLED", "true"
buildConfigField "String", "SELFUPDATE_URL", "\"http://anibreak.ru/v.0.3/get/openmanga/version\""
buildConfigField "String", "SYNC_URL", "\"http://openmanga.pythonanywhere.com/api/v1\""
Expand Down Expand Up @@ -87,7 +87,7 @@ android {
}
}

def work_version = "2.0.1"
def work_version = "2.0.1" //TODO upgrade

dependencies {

Expand All @@ -96,7 +96,7 @@ dependencies {
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.exifinterface:exifinterface:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'

// worker
implementation "androidx.work:work-runtime-ktx:$work_version"
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/java/org/nv95/openmanga/di/FeatureModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ package org.nv95.openmanga.di
import androidx.lifecycle.LifecycleOwner
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.koin.core.qualifier.TypeQualifier
import org.koin.core.qualifier.named
import org.koin.dsl.module
import org.nv95.openmanga.core.errorhandler.DefaultErrorHandler
import org.nv95.openmanga.core.errorhandler.ErrorHandlerContainer
import org.nv95.openmanga.core.exeption.ErrorExceptionMessage
import org.nv95.openmanga.core.extention.loge
import org.nv95.openmanga.core.fragment.BaseView
import org.nv95.openmanga.core.lifecycle.JobController
import org.nv95.openmanga.di.qualifier.SupperCoroutine


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import org.koin.dsl.module
import org.nv95.openmanga.feature.newchapter.view.NewChapterViewModel


val newChapterModule = module {
val newChapterModule = module(override = true) {

viewModel {
NewChapterViewModel(
favouritesProvider = get(),
newChaptersProvider = get(),
connectionSource = get(),
mainContext = get()
)
}
viewModel {
NewChapterViewModel(
favouritesProvider = get(),
newChaptersProvider = get(),
connectionSource = get(),
mainContext = get()
)
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.nv95.openmanga.feature.newchapter.view

import android.os.Bundle
import android.view.*
import android.view.MenuItem
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.fragment_updates.*
import kotlinx.android.synthetic.main.fragment_updates.view.*
import org.koin.androidx.scope.currentScope
import org.koin.androidx.viewmodel.ext.android.getViewModel
import org.nv95.openmanga.R
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/org/nv95/openmanga/services/ImportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
import android.os.AsyncTask;
import android.os.IBinder;
import android.os.PowerManager;
import androidx.annotation.Nullable;
import android.widget.Toast;

import androidx.annotation.Nullable;

import org.nv95.openmanga.R;
import org.nv95.openmanga.helpers.DirRemoveHelper;
import org.nv95.openmanga.helpers.NotificationHelper;
import org.nv95.openmanga.utils.ChangesObserver;
import org.nv95.openmanga.utils.FileLogger;
import org.nv95.openmanga.utils.MangaStore;
import org.nv95.openmanga.utils.NaturalOrderComparator;
import org.nv95.openmanga.utils.StorageUtils;
import org.nv95.openmanga.utils.ZipBuilder;

Expand All @@ -25,6 +27,8 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
Expand Down Expand Up @@ -58,7 +62,8 @@ public void onCreate() {
new Intent(this, ImportService.class).putExtra("action", ACTION_CANCEL),
0));
startForeground(NOTIFY_ID, mNotificationHelper.notification());
mWakeLock = ((PowerManager) getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Saving manga");
mWakeLock = ((PowerManager) getSystemService(POWER_SERVICE))
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "openmanga::saving");
mWakeLock.acquire();
}

Expand Down Expand Up @@ -157,6 +162,12 @@ protected Integer doInBackground(String... params) {
//importing
MangaStore ms = new MangaStore(ImportService.this);
ContentValues cv;
final ZipEntry[] all = ZipBuilder.enumerateEntries(params[0]);
final ArrayList<String> names = new ArrayList<>(all.length);
for (ZipEntry zipEntry : all) {
names.add(zipEntry.getName());
}
Collections.sort(names, new NaturalOrderComparator());
//all pages
chapterId = mangaId;
File outFile;
Expand All @@ -179,7 +190,7 @@ protected Integer doInBackground(String... params) {
cv.put("chapterid", chapterId);
cv.put("mangaid", mangaId);
cv.put("file", outFile.getName());
cv.put("number", pages);
cv.put("number", names.indexOf(entry.getName()));
ms.getDatabase(true).insert(TABLE_PAGES, null, cv);
pages++;
publishProgress(pages, total);
Expand Down
142 changes: 142 additions & 0 deletions app/src/main/java/org/nv95/openmanga/utils/NaturalOrderComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package org.nv95.openmanga.utils;

/*
NaturalOrderComparator.java -- Perform 'natural order' comparisons of strings in Java.
Copyright (C) 2003 by Pierre-Luc Paour <[email protected]>

Based on the C version by Martin Pool, of which this is more or less a straight conversion.
Copyright (C) 2000 by Martin Pool <[email protected]>

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

import java.util.Comparator;

public class NaturalOrderComparator implements Comparator<String> {
int compareRight(String a, String b) {
int bias = 0, ia = 0, ib = 0;

// The longest run of digits wins. That aside, the greatest
// value wins, but we can't know that it will until we've scanned
// both numbers to know that they have the same magnitude, so we
// remember it in BIAS.
for (; ; ia++, ib++) {
char ca = charAt(a, ia);
char cb = charAt(b, ib);

if (!isDigit(ca) && !isDigit(cb)) {
return bias;
}
if (!isDigit(ca)) {
return -1;
}
if (!isDigit(cb)) {
return +1;
}
if (ca == 0 && cb == 0) {
return bias;
}

if (bias == 0) {
if (ca < cb) {
bias = -1;
} else if (ca > cb) {
bias = +1;
}
}
}
}

public int compare(String a, String b) {

int ia = 0, ib = 0;
int nza = 0, nzb = 0;
char ca, cb;

while (true) {
// Only count the number of zeroes leading the last number compared
nza = nzb = 0;

ca = charAt(a, ia);
cb = charAt(b, ib);

// skip over leading spaces or zeros
while (Character.isSpaceChar(ca) || ca == '0') {
if (ca == '0') {
nza++;
} else {
// Only count consecutive zeroes
nza = 0;
}

ca = charAt(a, ++ia);
}

while (Character.isSpaceChar(cb) || cb == '0') {
if (cb == '0') {
nzb++;
} else {
// Only count consecutive zeroes
nzb = 0;
}

cb = charAt(b, ++ib);
}

// Process run of digits
if (Character.isDigit(ca) && Character.isDigit(cb)) {
int bias = compareRight(a.substring(ia), b.substring(ib));
if (bias != 0) {
return bias;
}
}

if (ca == 0 && cb == 0) {
// The strings compare the same. Perhaps the caller
// will want to call strcmp to break the tie.
return compareEqual(a, b, nza, nzb);
}
if (ca < cb) {
return -1;
}
if (ca > cb) {
return +1;
}

++ia;
++ib;
}
}

static boolean isDigit(char c) {
return Character.isDigit(c) || c == '.' || c == ',';
}

static char charAt(String s, int i) {
return i >= s.length() ? 0 : s.charAt(i);
}

static int compareEqual(String a, String b, int nza, int nzb) {
if (nza - nzb != 0)
return nza - nzb;

if (a.length() == b.length())
return a.compareTo(b);

return a.length() - b.length();
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.41'
ext.kotlin_version = '1.3.50'
ext.koin_version = '2.0.1'
repositories {
jcenter()
google()
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0-rc02'
classpath 'com.android.tools.build:gradle:3.5.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down