mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
code simplification + introduced MissingBookActivity
This commit is contained in:
parent
d79e31eb87
commit
9d0166d9a7
11 changed files with 81 additions and 47 deletions
|
@ -15,6 +15,7 @@
|
|||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
<include layout="@layout/ok_cancel_buttons" android:id="@+id/simple_dialog_buttons" />
|
||||
</LinearLayout>
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
>
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/simple_dialog_text"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
<include layout="@layout/ok_cancel_buttons" android:id="@+id/simple_dialog_buttons" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
|
@ -29,7 +29,6 @@ public class MissingNativeLibraryActivity extends SimpleDialogActivity {
|
|||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setSimpleContentView(false);
|
||||
|
||||
final ZLResource resource = ZLResource.resource("crash").getResource("missingNativeLibrary");
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ public class BookReadingErrorActivity extends SimpleDialogActivity implements Er
|
|||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
setSimpleContentView(false);
|
||||
|
||||
final ZLResource resource = ZLResource.resource("error").getResource("bookReading");
|
||||
setTitle(resource.getResource("title").getValue());
|
||||
|
|
|
@ -69,7 +69,7 @@ public class BookDownloader extends Activity {
|
|||
}
|
||||
if ("epub".equals(uri.getScheme())) {
|
||||
uri = uri.buildUpon().scheme("http").build();
|
||||
intent.putExtra(BookDownloaderService.BOOK_MIME, MimeType.APP_EPUB_ZIP.toString());
|
||||
intent.putExtra(BookDownloaderService.Key.BOOK_MIME, MimeType.APP_EPUB_ZIP.toString());
|
||||
}
|
||||
|
||||
startService(
|
||||
|
|
|
@ -45,10 +45,13 @@ import org.geometerplus.android.fbreader.network.auth.ServiceNetworkContext;
|
|||
public class BookDownloaderService extends Service {
|
||||
private final ZLNetworkContext myNetworkContext = new ServiceNetworkContext(this);
|
||||
|
||||
public static final String BOOK_MIME = "fbreader.book.mime";
|
||||
public interface Key {
|
||||
String BOOK_TITLE = "org.geometerplus.android.fbreader.network.Title";
|
||||
String BOOK_MIME = "fbreader.book.mime";
|
||||
}
|
||||
|
||||
public static final String REFERENCE_TYPE_KEY = "org.geometerplus.android.fbreader.network.ReferenceType";
|
||||
public static final String CLEAN_URL_KEY = "org.geometerplus.android.fbreader.network.CleanURL";
|
||||
public static final String TITLE_KEY = "org.geometerplus.android.fbreader.network.Title";
|
||||
|
||||
public static final String SHOW_NOTIFICATIONS_KEY = "org.geometerplus.android.fbreader.network.ShowNotifications";
|
||||
|
||||
|
@ -112,7 +115,7 @@ public class BookDownloaderService extends Service {
|
|||
final int notifications = intent.getIntExtra(SHOW_NOTIFICATIONS_KEY, 0);
|
||||
|
||||
final String url = uri.toString();
|
||||
final MimeType mime = MimeType.get(intent.getStringExtra(BOOK_MIME));
|
||||
final MimeType mime = MimeType.get(intent.getStringExtra(Key.BOOK_MIME));
|
||||
UrlInfo.Type referenceType = (UrlInfo.Type)intent.getSerializableExtra(REFERENCE_TYPE_KEY);
|
||||
if (referenceType == null) {
|
||||
referenceType = UrlInfo.Type.Book;
|
||||
|
@ -165,7 +168,7 @@ public class BookDownloaderService extends Service {
|
|||
startActivity(getFBReaderIntent(fileFile));
|
||||
return;
|
||||
}
|
||||
String title = intent.getStringExtra(TITLE_KEY);
|
||||
String title = intent.getStringExtra(Key.BOOK_TITLE);
|
||||
if (title == null || title.length() == 0) {
|
||||
title = fileFile.getName();
|
||||
}
|
||||
|
|
|
@ -104,8 +104,6 @@ public class BuyBooksActivity extends SimpleDialogActivity implements NetworkLib
|
|||
return;
|
||||
}
|
||||
|
||||
setSimpleContentView(true);
|
||||
|
||||
try {
|
||||
if (!mgr.isAuthorised(true)) {
|
||||
buttonsView().setVisibility(View.GONE);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.geometerplus.android.fbreader.network;
|
||||
|
||||
class NetworkNotifications {
|
||||
public class NetworkNotifications {
|
||||
private static NetworkNotifications ourInstance;
|
||||
|
||||
public static NetworkNotifications Instance() {
|
||||
|
@ -32,10 +32,8 @@ class NetworkNotifications {
|
|||
//private static final int CATALOG_LOADING = 0;
|
||||
//private static final int NETWORK_SEARCH = 1;
|
||||
|
||||
private static final int BOOK_DOWNLOADING_START = 0x10000000;
|
||||
private static final int BOOK_DOWNLOADING_END = 0x1fffffff;
|
||||
|
||||
private volatile int myBookDownloadingId = BOOK_DOWNLOADING_START;
|
||||
public static final int MISSING_BOOK_ID = 0x0fffffff;
|
||||
private volatile int myBookDownloadingId = 0x10000000;
|
||||
|
||||
private NetworkNotifications() {
|
||||
}
|
||||
|
@ -49,12 +47,6 @@ class NetworkNotifications {
|
|||
}*/
|
||||
|
||||
public synchronized int getBookDownloadingId() {
|
||||
final int id = myBookDownloadingId;
|
||||
if (myBookDownloadingId == BOOK_DOWNLOADING_END) {
|
||||
myBookDownloadingId = BOOK_DOWNLOADING_START;
|
||||
} else {
|
||||
++myBookDownloadingId;
|
||||
}
|
||||
return id;
|
||||
return ++myBookDownloadingId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,10 +133,10 @@ public abstract class Util implements UserRegistrationConstants {
|
|||
activity.startService(
|
||||
new Intent(Intent.ACTION_VIEW, Uri.parse(ref.Url),
|
||||
activity.getApplicationContext(), BookDownloaderService.class)
|
||||
.putExtra(BookDownloaderService.BOOK_MIME, ref.Mime.toString())
|
||||
.putExtra(BookDownloaderService.Key.BOOK_MIME, ref.Mime.toString())
|
||||
.putExtra(BookDownloaderService.REFERENCE_TYPE_KEY, resolvedType)
|
||||
.putExtra(BookDownloaderService.CLEAN_URL_KEY, ref.cleanUrl())
|
||||
.putExtra(BookDownloaderService.TITLE_KEY, book.Title)
|
||||
.putExtra(BookDownloaderService.Key.BOOK_TITLE, book.Title)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2014 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.android.fbreader.sync;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.android.fbreader.network.BookDownloaderService;
|
||||
import org.geometerplus.android.fbreader.network.NetworkNotifications;
|
||||
import org.geometerplus.android.fbreader.util.SimpleDialogActivity;
|
||||
|
||||
public class MissingBookActivity extends SimpleDialogActivity {
|
||||
public static String errorMessage(String title) {
|
||||
return ZLResource.resource("errorMessage").getResource("bookIsMissing").getValue()
|
||||
.replace("%s", title);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
final String title = intent.getStringExtra(BookDownloaderService.Key.BOOK_TITLE);
|
||||
setTitle(title);
|
||||
textView().setText(errorMessage(title));
|
||||
intent.setClass(this, BookDownloaderService.class);
|
||||
|
||||
okButton().setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
final NotificationManager notificationManager =
|
||||
(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
notificationManager.cancel(NetworkNotifications.MISSING_BOOK_ID);
|
||||
startService(intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
cancelButton().setOnClickListener(finishListener());
|
||||
setButtonTexts("download", "cancel");
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
package org.geometerplus.android.fbreader.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
@ -35,12 +36,14 @@ public abstract class SimpleDialogActivity extends Activity {
|
|||
private ZLResource myButtonsResource;
|
||||
private View.OnClickListener myFinishListener;
|
||||
|
||||
protected final void setSimpleContentView(boolean med) {
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
myTextView = null;
|
||||
myButtonsView = null;
|
||||
myOkButton = null;
|
||||
myCancelButton = null;
|
||||
setContentView(med ? R.layout.simple_dialog_medium_text : R.layout.simple_dialog);
|
||||
setContentView(R.layout.simple_dialog);
|
||||
}
|
||||
|
||||
protected final TextView textView() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue