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

Commit

Permalink
fix ninemanga error and added fileProvider for android nougat or grea…
Browse files Browse the repository at this point in the history
…ter update
  • Loading branch information
raulhaag committed Oct 28, 2017
1 parent 3e79671 commit 1ca5937
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ android {
defaultConfig {
applicationId "ar.rulosoft.mimanganu"
minSdkVersion 14
targetSdkVersion 25
versionCode 72
versionName "1.72"
targetSdkVersion 24
versionCode 71
versionName "1.71"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
android:label="@string/app_name"
android:largeHeap="true">

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="ar.rulosoft.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>

<!--
Better if app starts dark and turns white than blinds you with white splash screen
before it turns dark.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private static void generateNeededCookie() {
Cookie.parse(url, "__utmz=128769555." + aTime
+ ".1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); Domain=ninemanga.com")
));
cookieInit = true;
}

@Override
Expand Down Expand Up @@ -214,7 +215,7 @@ public String getImageFrom(Chapter chapter, int page) throws Exception {
+ page + ".html"));
data = getFirstMatch(PATTERN_IMAGE, data,
context.getString(R.string.server_failed_loading_image));
if (data.contains("//")) {
if (data.contains("////")) {
throw new Exception(context.getString(R.string.server_failed_loading_image));
}
return data;
Expand Down Expand Up @@ -290,7 +291,7 @@ public ArrayList<Manga> getMangasFiltered(int[][] filters, int pageNumber) throw
* @throws Exception if an error occurred
*/
private Navigator getNavigatorWithNeededHeader() throws Exception {
if (cookieInit) {
if (!cookieInit) {
generateNeededCookie();
}
Navigator nav = Navigator.getInstance();
Expand Down
20 changes: 15 additions & 5 deletions app/src/main/java/ar/rulosoft/mimanganu/utils/UpdateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
Expand All @@ -23,6 +26,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
import java.util.concurrent.TimeUnit;

import ar.rulosoft.mimanganu.MessageActivity;
Expand Down Expand Up @@ -150,13 +154,13 @@ protected Void doInBackground(Void... voids) {
Response response = client.newCall(new Request.Builder().url(url).build()).execute();
InputStream inputStream = response.body().byteStream();
FileOutputStream outputStream = new FileOutputStream(UPDATE_FILE_CACHE);
long lenghtOfFile = response.body().contentLength();
long lengthOfFile = response.body().contentLength();
int count;
byte data[] = new byte[1024 * 6];
long total = 0;
while ((count = inputStream.read(data)) != -1) {
total += count;
int tprog = (int) ((total * 100) / lenghtOfFile);
int tprog = (int) ((total * 100) / lengthOfFile);
if (tprog > prog) {
prog = tprog;
activity.runOnUiThread(new Runnable() {
Expand All @@ -174,7 +178,7 @@ public void run() {
}
outputStream.close();
inputStream.close();
activity.startActivity(getUpdateIntent());
activity.startActivity(getUpdateIntent(activity));
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Expand All @@ -197,9 +201,15 @@ public void run() {
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

private static Intent getUpdateIntent() {
private static Intent getUpdateIntent(Context context) {
Uri contentUri = FileProvider.getUriForFile(context, "ar.rulosoft.provider", UPDATE_FILE_CACHE);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(UPDATE_FILE_CACHE), "application/vnd.android.package-archive");
intent.setDataAndType(contentUri, "application/vnd.android.package-archive");
List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
context.grantUriPermission(packageName, contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
return intent;
}

Expand Down

0 comments on commit 1ca5937

Please sign in to comment.