Merge pull request #3644 from ByteHamster/crash-fix

Various tiny crash fixes and improvements reported on Google Play
This commit is contained in:
H. Lehmann 2019-11-26 16:18:06 +01:00 committed by GitHub
commit fd1e510106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 19 deletions

View File

@ -89,7 +89,6 @@ public class SubscriptionFragment extends Fragment {
subscriptionGridLayout.setNumColumns(prefs.getInt(PREF_NUM_COLUMNS, 3));
registerForContextMenu(subscriptionGridLayout);
subscriptionAddButton = root.findViewById(R.id.subscriptions_add);
setupEmptyView();
return root;
}
@ -154,6 +153,7 @@ public class SubscriptionFragment extends Fragment {
subscriptionAdapter = new SubscriptionsAdapter((MainActivity) getActivity(), itemAccess);
subscriptionGridLayout.setAdapter(subscriptionAdapter);
subscriptionGridLayout.setOnItemClickListener(subscriptionAdapter);
setupEmptyView();
subscriptionAddButton.setOnClickListener(view -> {
if (getActivity() instanceof MainActivity) {

View File

@ -1,8 +1,10 @@
package de.danoeh.antennapod.view;
import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.drawable.Drawable;
import android.widget.AbsListView;
import android.widget.ListAdapter;
import androidx.annotation.AttrRes;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
@ -17,8 +19,9 @@ import de.danoeh.antennapod.R;
public class EmptyViewHandler {
private boolean layoutAdded = false;
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private View list;
private ListAdapter listAdapter;
private RecyclerView.Adapter recyclerAdapter;
private final Context context;
private final View emptyView;
@ -60,7 +63,9 @@ public class EmptyViewHandler {
}
addToParentView(listView);
layoutAdded = true;
this.list = listView;
listView.setEmptyView(emptyView);
updateAdapter(listView.getAdapter());
}
public void attachToRecyclerView(RecyclerView recyclerView) {
@ -69,7 +74,7 @@ public class EmptyViewHandler {
}
addToParentView(recyclerView);
layoutAdded = true;
this.recyclerView = recyclerView;
this.list = recyclerView;
updateAdapter(recyclerView.getAdapter());
}
@ -85,16 +90,27 @@ public class EmptyViewHandler {
}
public void updateAdapter(RecyclerView.Adapter adapter) {
if (this.adapter != null) {
this.adapter.unregisterAdapterDataObserver(adapterObserver);
if (this.recyclerAdapter != null) {
this.recyclerAdapter.unregisterAdapterDataObserver(adapterObserver);
}
this.adapter = adapter;
this.recyclerAdapter = adapter;
if (adapter != null) {
adapter.registerAdapterDataObserver(adapterObserver);
}
updateVisibility();
}
private void updateAdapter(ListAdapter adapter) {
if (this.listAdapter != null) {
this.listAdapter.unregisterDataSetObserver(listAdapterObserver);
}
this.listAdapter = adapter;
if (adapter != null) {
adapter.registerDataSetObserver(listAdapterObserver);
}
updateVisibility();
}
private final SimpleAdapterDataObserver adapterObserver = new SimpleAdapterDataObserver() {
@Override
public void anythingChanged() {
@ -102,14 +118,22 @@ public class EmptyViewHandler {
}
};
private final DataSetObserver listAdapterObserver = new DataSetObserver() {
public void onChanged() {
updateVisibility();
}
};
public void updateVisibility() {
boolean empty;
if (adapter == null) {
empty = true;
if (recyclerAdapter != null) {
empty = recyclerAdapter.getItemCount() == 0;
} else if (listAdapter != null) {
empty = listAdapter.isEmpty();
} else {
empty = adapter.getItemCount() == 0;
empty = true;
}
recyclerView.setVisibility(empty ? View.GONE : View.VISIBLE);
list.setVisibility(empty ? View.GONE : View.VISIBLE);
emptyView.setVisibility(empty ? View.VISIBLE : View.GONE);
}
}

View File

@ -49,7 +49,7 @@ public class AntennapodHttpClient {
private static final String TAG = "AntennapodHttpClient";
private static final int CONNECTION_TIMEOUT = 30000;
private static final int CONNECTION_TIMEOUT = 10000;
private static final int READ_TIMEOUT = 30000;
private static final int MAX_CONNECTIONS = 8;

View File

@ -138,7 +138,7 @@ public class DownloadService extends Service {
requester = DownloadRequester.getInstance();
syncExecutor = Executors.newSingleThreadExecutor(r -> {
Thread t = new Thread(r);
Thread t = new Thread(r, "SyncThread");
t.setPriority(Thread.MIN_PRIORITY);
return t;
});
@ -146,7 +146,7 @@ public class DownloadService extends Service {
downloadExecutor = new ExecutorCompletionService<>(
Executors.newFixedThreadPool(UserPreferences.getParallelDownloads(),
r -> {
Thread t = new Thread(r);
Thread t = new Thread(r, "DownloadThread");
t.setPriority(Thread.MIN_PRIORITY);
return t;
}
@ -154,7 +154,7 @@ public class DownloadService extends Service {
);
schedExecutor = new ScheduledThreadPoolExecutor(SCHED_EX_POOL_SIZE,
r -> {
Thread t = new Thread(r);
Thread t = new Thread(r, "DownloadSchedExecutorThread");
t.setPriority(Thread.MIN_PRIORITY);
return t;
}, (r, executor) -> Log.w(TAG, "SchedEx rejected submission of new task")
@ -163,11 +163,15 @@ public class DownloadService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null &&
intent.getParcelableArrayListExtra(EXTRA_REQUESTS) != null) {
if (intent != null && intent.getParcelableArrayListExtra(EXTRA_REQUESTS) != null) {
Notification notification = notificationManager.updateNotifications(
requester.getNumberOfDownloads(), downloads);
startForeground(NOTIFICATION_ID, notification);
onDownloadQueued(intent);
} else if (numberOfDownloads.get() == 0) {
stopSelf();
} else {
Log.d(TAG, "onStartCommand: Unknown intent");
}
return Service.START_NOT_STICKY;
}
@ -217,7 +221,9 @@ public class DownloadService extends Service {
syncExecutor.shutdown();
schedExecutor.shutdown();
cancelNotificationUpdater();
downloadPostFuture.cancel(true);
if (downloadPostFuture != null) {
downloadPostFuture.cancel(true);
}
unregisterReceiver(cancelDownloadReceiver);
// if this was the initial gpodder sync, i.e. we just synced the feeds successfully,

View File

@ -202,7 +202,9 @@ public class DownloadRequester implements DownloadStateProvider {
DownloadRequest request = createRequest(feed, null, new File(getFeedfilePath(), getFeedfileName(feed)),
true, username, password, lastModified, true, args);
download(context, request);
if (request != null) {
download(context, request);
}
}
}