mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
Buttons in NetworkBookInfoActivity implementation
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1260 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
f1a8d3bb74
commit
0ef33928a8
9 changed files with 172 additions and 71 deletions
|
@ -40,6 +40,7 @@
|
|||
<activity android:name="org.geometerplus.android.fbreader.network.NetworkLibraryActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" />
|
||||
<service android:name="org.geometerplus.android.fbreader.network.CatalogDownloaderService" android:process=":networkLibrary" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.NetworkBookInfoActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.BookDownloaderCallback" android:process=":networkLibrary" android:theme="@android:style/Theme.NoDisplay" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.TOCActivity" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.BookmarksActivity" android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookmarkSearchActivity" />
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
<activity android:name="org.geometerplus.android.fbreader.network.NetworkLibraryActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" />
|
||||
<service android:name="org.geometerplus.android.fbreader.network.CatalogDownloaderService" android:process=":networkLibrary" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.NetworkBookInfoActivity" android:process=":networkLibrary" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.network.BookDownloaderCallback" android:process=":networkLibrary" android:theme="@android:style/Theme.NoDisplay" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.TOCActivity" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.BookmarksActivity" android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookmarkSearchActivity" />
|
||||
|
|
|
@ -10,42 +10,48 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:paddingTop="4dip"
|
||||
android:paddingLeft="2dip"
|
||||
android:paddingRight="2dip"
|
||||
android:paddingTop="4dip"
|
||||
android:paddingLeft="2dip"
|
||||
android:paddingRight="2dip"
|
||||
android:baselineAligned="false"
|
||||
>
|
||||
<LinearLayout
|
||||
android:id="@+id/network_book_left_spacer"
|
||||
android:layout_weight="0.25"
|
||||
android:layout_weight="0.5"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone" />
|
||||
android:visibility="gone"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/network_book_button0"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="2"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/network_book_button1"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="2"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<Button
|
||||
android:id="@+id/network_book_button2"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:maxLines="2"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/network_book_right_spacer"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="0.25"
|
||||
android:layout_weight="0.5"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone" />
|
||||
android:visibility="gone"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<ScrollView
|
||||
android:layout_width="fill_parent"
|
||||
|
|
|
@ -60,7 +60,7 @@ class AuthenticationDialog {
|
|||
myLink = link;
|
||||
myErrorMessage = null;
|
||||
myOnSuccessRunnable = onSuccessRunnable;
|
||||
NetworkLibraryActivity.Instance.showDialog(NetworkLibraryActivity.DIALOG_AUTHENTICATION);
|
||||
NetworkLibraryActivity.Instance.getTopLevelActivity().showDialog(NetworkLibraryActivity.DIALOG_AUTHENTICATION);
|
||||
}
|
||||
|
||||
public Dialog createDialog(final Activity activity) {
|
||||
|
@ -88,8 +88,10 @@ class AuthenticationDialog {
|
|||
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||
library.invalidateAccountDependents();
|
||||
library.synchronize();
|
||||
((NetworkLibraryActivity) activity).getAdapter().resetTree();
|
||||
((NetworkLibraryActivity) activity).getListView().invalidateViews();
|
||||
if (NetworkLibraryActivity.Instance != null) {
|
||||
NetworkLibraryActivity.Instance.getAdapter().resetTree();
|
||||
NetworkLibraryActivity.Instance.fireOnModelChanged();
|
||||
}
|
||||
if (message.what < 0) {
|
||||
myErrorMessage = (String) message.obj;
|
||||
activity.showDialog(NetworkLibraryActivity.DIALOG_AUTHENTICATION);
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (C) 2010 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.network;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
|
||||
public class BookDownloaderCallback extends Activity {
|
||||
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
if (NetworkLibraryActivity.Instance != null) {
|
||||
NetworkLibraryActivity.Instance.fireOnModelChanged();
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}
|
|
@ -192,7 +192,7 @@ public class BookDownloaderService extends Service {
|
|||
}
|
||||
|
||||
private Intent getFBReaderIntent(final File file) {
|
||||
final Intent intent = new Intent(this, org.geometerplus.android.fbreader.FBReader.class);
|
||||
final Intent intent = new Intent(getApplicationContext(), org.geometerplus.android.fbreader.FBReader.class);
|
||||
if (file != null) {
|
||||
intent.setAction(Intent.ACTION_VIEW).setData(Uri.fromFile(file));
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ public class BookDownloaderService extends Service {
|
|||
System.currentTimeMillis()
|
||||
);
|
||||
notification.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||
final Intent intent = getFBReaderIntent(success ? file : null);
|
||||
final Intent intent = success ? getFBReaderIntent(file) : new Intent();
|
||||
final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
|
||||
notification.setLatestEventInfo(getApplicationContext(), title, contentText, contentIntent);
|
||||
return notification;
|
||||
|
@ -225,8 +225,7 @@ public class BookDownloaderService extends Service {
|
|||
contentView.setTextViewText(R.id.download_notification_progress_text, "");
|
||||
contentView.setProgressBar(R.id.download_notification_progress_bar, 100, 0, true);
|
||||
|
||||
final Intent intent = getFBReaderIntent(null);
|
||||
final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
|
||||
final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
|
||||
|
||||
final Notification notification = new Notification();
|
||||
notification.icon = android.R.drawable.stat_sys_download;
|
||||
|
@ -237,8 +236,16 @@ public class BookDownloaderService extends Service {
|
|||
return notification;
|
||||
}
|
||||
|
||||
private void startCallbackActivity() {
|
||||
startActivity(
|
||||
new Intent(getApplicationContext(), BookDownloaderCallback.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
);
|
||||
}
|
||||
|
||||
private void startFileDownload(final String urlString, final String sslCertificate, final File file, final String title) {
|
||||
myDownloadingURLs.add(urlString);
|
||||
startCallbackActivity();
|
||||
|
||||
final int notificationId = (int) System.currentTimeMillis(); // notification unique identifier
|
||||
final Notification progressNotification = createDownloadProgressNotification(title);
|
||||
|
@ -274,6 +281,7 @@ public class BookDownloaderService extends Service {
|
|||
notificationId,
|
||||
createDownloadFinishNotification(file, title, message.what != 0)
|
||||
);
|
||||
startCallbackActivity();
|
||||
doStop();
|
||||
}
|
||||
};
|
||||
|
@ -331,10 +339,10 @@ public class BookDownloaderService extends Service {
|
|||
final String err = ZLNetworkManager.Instance().perform(request);
|
||||
// TODO: show error message to User
|
||||
final boolean success = (err == null);
|
||||
downloadFinishHandler.sendEmptyMessage(success ? 1 : 0);
|
||||
if (!success) {
|
||||
file.delete();
|
||||
}
|
||||
downloadFinishHandler.sendEmptyMessage(success ? 1 : 0);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
|
|
@ -210,7 +210,7 @@ class NetworkBookActions extends NetworkTreeActions {
|
|||
} else {
|
||||
sslCertificate = null;
|
||||
}
|
||||
NetworkLibraryActivity.Instance.startService(
|
||||
NetworkLibraryActivity.Instance.getTopLevelActivity().startService(
|
||||
new Intent(Intent.ACTION_VIEW, Uri.parse(ref.URL),
|
||||
NetworkLibraryActivity.Instance.getApplicationContext(), BookDownloaderService.class)
|
||||
.putExtra(BookDownloaderService.BOOK_FORMAT_KEY, ref.BookFormat)
|
||||
|
@ -233,7 +233,7 @@ class NetworkBookActions extends NetworkTreeActions {
|
|||
}
|
||||
}
|
||||
if (local != null) {
|
||||
NetworkLibraryActivity.Instance.startActivity(
|
||||
NetworkLibraryActivity.Instance.getTopLevelActivity().startActivity(
|
||||
new Intent(Intent.ACTION_VIEW,
|
||||
Uri.fromFile(new File(local)),
|
||||
NetworkLibraryActivity.Instance.getApplicationContext(),
|
||||
|
@ -265,6 +265,7 @@ class NetworkBookActions extends NetworkTreeActions {
|
|||
}
|
||||
}
|
||||
}
|
||||
NetworkLibraryActivity.Instance.fireOnModelChanged();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(buttonResource.getResource("no").getValue(), null)
|
||||
|
@ -312,19 +313,20 @@ class NetworkBookActions extends NetworkTreeActions {
|
|||
}
|
||||
if (NetworkLibraryActivity.Instance != null) {
|
||||
NetworkLibraryActivity.Instance.getAdapter().resetTree();
|
||||
NetworkLibraryActivity.Instance.fireOnModelChanged();
|
||||
}
|
||||
}
|
||||
};
|
||||
}; // end Handler
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
String err = mgr.purchaseBook(book);
|
||||
handler.sendMessage(handler.obtainMessage(0, err));
|
||||
}
|
||||
};
|
||||
}; // end Runnable
|
||||
((ZLAndroidDialogManager)ZLAndroidDialogManager.Instance()).wait("purchaseBook", runnable, NetworkLibraryActivity.Instance.getTopLevelActivity());
|
||||
}
|
||||
}
|
||||
};
|
||||
} // end if
|
||||
} // end onClick
|
||||
}; // end listener
|
||||
|
||||
final Runnable buyRunnable = new Runnable() {
|
||||
public void run() {
|
||||
|
|
|
@ -22,8 +22,10 @@ package org.geometerplus.android.fbreader.network;
|
|||
import java.util.Set;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Button;
|
||||
|
@ -42,7 +44,7 @@ import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;
|
|||
import org.geometerplus.fbreader.network.*;
|
||||
|
||||
|
||||
public class NetworkBookInfoActivity extends Activity {
|
||||
public class NetworkBookInfoActivity extends Activity implements NetworkLibraryActivity.EventListener {
|
||||
|
||||
private NetworkBookItem myBook;
|
||||
|
||||
|
@ -128,11 +130,15 @@ public class NetworkBookInfoActivity extends Activity {
|
|||
}
|
||||
|
||||
private final void setupButtons() {
|
||||
final int buttonCount = 3;
|
||||
final int buttons[] = new int[] {
|
||||
R.id.network_book_button0,
|
||||
R.id.network_book_button1,
|
||||
R.id.network_book_button2,
|
||||
};
|
||||
int buttonNumber = 0;
|
||||
Set<NetworkBookActions.Action> actions = NetworkBookActions.getContextMenuActions(myBook);
|
||||
for (final NetworkBookActions.Action a: actions) {
|
||||
if (buttonNumber >= buttonCount) {
|
||||
if (buttonNumber >= buttons.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -144,42 +150,30 @@ public class NetworkBookInfoActivity extends Activity {
|
|||
text = resource.getResource(a.Key).getValue().replace("%s", a.Arg);
|
||||
}
|
||||
|
||||
final String buttonName = "network_book_button" + buttonNumber++;
|
||||
try {
|
||||
int buttonId = R.id.class.getDeclaredField(buttonName).getInt(null);
|
||||
Button button = (Button) findViewById(buttonId);
|
||||
button.setText(text);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
NetworkBookActions.runAction(myBook, a.Id);
|
||||
NetworkBookInfoActivity.this.updateView();
|
||||
}
|
||||
});
|
||||
} catch (NoSuchFieldException ex) {
|
||||
} catch (SecurityException ex) {
|
||||
} catch (IllegalAccessException ex) {
|
||||
} catch (IllegalArgumentException ex) {
|
||||
}
|
||||
final int buttonId = buttons[buttonNumber++];
|
||||
Button button = (Button) findViewById(buttonId);
|
||||
button.setText(text);
|
||||
button.setVisibility(View.VISIBLE);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
NetworkBookActions.runAction(myBook, a.Id);
|
||||
NetworkBookInfoActivity.this.updateView();
|
||||
}
|
||||
});
|
||||
button.setEnabled(a.Id != NetworkTreeActions.TREE_NO_ACTION);
|
||||
}
|
||||
boolean showSpacers = buttonNumber == 1;
|
||||
findViewById(R.id.network_book_left_spacer).setVisibility(showSpacers ? View.VISIBLE : View.GONE);
|
||||
findViewById(R.id.network_book_right_spacer).setVisibility(showSpacers ? View.VISIBLE : View.GONE);
|
||||
while (buttonNumber < buttonCount) {
|
||||
final String buttonName = "network_book_button" + buttonNumber++;
|
||||
try {
|
||||
int buttonId = R.id.class.getDeclaredField(buttonName).getInt(null);
|
||||
View button = findViewById(buttonId);
|
||||
button.setVisibility(View.GONE);
|
||||
button.setOnClickListener(null);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
} catch (SecurityException ex) {
|
||||
} catch (IllegalAccessException ex) {
|
||||
} catch (IllegalArgumentException ex) {
|
||||
}
|
||||
while (buttonNumber < buttons.length) {
|
||||
final int buttonId = buttons[buttonNumber++];
|
||||
View button = findViewById(buttonId);
|
||||
button.setVisibility(View.GONE);
|
||||
button.setOnClickListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
void updateView() {
|
||||
private void updateView() {
|
||||
setupButtons();
|
||||
final View rootView = findViewById(R.id.network_book_root);
|
||||
rootView.invalidate();
|
||||
|
@ -188,11 +182,42 @@ public class NetworkBookInfoActivity extends Activity {
|
|||
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
NetworkLibraryActivity.Instance.setTopLevelActivity(this);
|
||||
if (NetworkLibraryActivity.Instance != null) {
|
||||
NetworkLibraryActivity.Instance.setTopLevelActivity(this);
|
||||
NetworkLibraryActivity.Instance.addEventListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onStop() {
|
||||
NetworkLibraryActivity.Instance.setTopLevelActivity(null);
|
||||
if (NetworkLibraryActivity.Instance != null) {
|
||||
NetworkLibraryActivity.Instance.setTopLevelActivity(null);
|
||||
NetworkLibraryActivity.Instance.removeEventListener(this);
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
public void onModelChanged() {
|
||||
updateView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog(int id) {
|
||||
Dialog dialog = null;
|
||||
switch (id) {
|
||||
case NetworkLibraryActivity.DIALOG_AUTHENTICATION:
|
||||
dialog = AuthenticationDialog.Instance().createDialog(this);
|
||||
break;
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialog(int id, Dialog dialog) {
|
||||
super.onPrepareDialog(id, dialog);
|
||||
switch (id) {
|
||||
case NetworkLibraryActivity.DIALOG_AUTHENTICATION:
|
||||
AuthenticationDialog.Instance().prepareDialog(dialog);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,13 +107,33 @@ public class NetworkLibraryActivity extends ListActivity implements MenuItem.OnM
|
|||
}
|
||||
|
||||
|
||||
public interface EventListener {
|
||||
void onModelChanged();
|
||||
}
|
||||
|
||||
private LinkedList<EventListener> myEventListeners = new LinkedList<EventListener>();
|
||||
|
||||
public final void addEventListener(EventListener listener) {
|
||||
myEventListeners.add(listener);
|
||||
}
|
||||
|
||||
public final void removeEventListener(EventListener listener) {
|
||||
myEventListeners.remove(listener);
|
||||
}
|
||||
|
||||
final void fireOnModelChanged() {
|
||||
for (EventListener listener: myEventListeners) {
|
||||
listener.onModelChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private Activity myTopLevelActivity;
|
||||
|
||||
public Activity getTopLevelActivity() {
|
||||
public final Activity getTopLevelActivity() {
|
||||
return myTopLevelActivity;
|
||||
}
|
||||
|
||||
void setTopLevelActivity(Activity activity) {
|
||||
final void setTopLevelActivity(Activity activity) {
|
||||
if (activity == null) {
|
||||
myTopLevelActivity = this;
|
||||
} else {
|
||||
|
@ -124,17 +144,13 @@ public class NetworkLibraryActivity extends ListActivity implements MenuItem.OnM
|
|||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
Instance = this;
|
||||
myTopLevelActivity = this;
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
|
||||
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
}
|
||||
Instance = this;
|
||||
myTopLevelActivity = this;
|
||||
myEventListeners.clear();
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
||||
myConnection = new BookDownloaderServiceConnection();
|
||||
bindService(
|
||||
|
@ -144,6 +160,11 @@ public class NetworkLibraryActivity extends ListActivity implements MenuItem.OnM
|
|||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -172,13 +193,13 @@ public class NetworkLibraryActivity extends ListActivity implements MenuItem.OnM
|
|||
|
||||
@Override
|
||||
public void onStop() {
|
||||
unbindService(myConnection);
|
||||
myConnection = null;
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
unbindService(myConnection);
|
||||
myConnection = null;
|
||||
Instance = null;
|
||||
super.onDestroy();
|
||||
}
|
||||
|
@ -410,6 +431,7 @@ public class NetworkLibraryActivity extends ListActivity implements MenuItem.OnM
|
|||
return dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPrepareDialog(int id, Dialog dialog) {
|
||||
super.onPrepareDialog(id, dialog);
|
||||
switch (id) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue