Remove lint warnings and Hungarian notations

This commit is contained in:
Abdul Wadood 2019-02-13 22:09:16 +05:30 committed by Isaac Hutt
parent cec66926e6
commit 2fb1100148
6 changed files with 110 additions and 110 deletions

View File

@ -34,6 +34,7 @@ import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
@ -58,20 +59,19 @@ import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
public class DownloadFragment extends BaseFragment { public class DownloadFragment extends BaseFragment {
public static LinkedHashMap<Integer, LibraryNetworkEntity.Book> mDownloads = public static LinkedHashMap<Integer, LibraryNetworkEntity.Book> downloads =
new LinkedHashMap<>(); new LinkedHashMap<>();
public static LinkedHashMap<Integer, String> mDownloadFiles = new LinkedHashMap<>(); public static LinkedHashMap<Integer, String> downloadFiles = new LinkedHashMap<>();
public static DownloadAdapter downloadAdapter; static DownloadAdapter downloadAdapter;
public RelativeLayout relLayout; ListView listView;
public ListView listView;
CoordinatorLayout mainLayout;
@Inject @Inject
SharedPreferenceUtil sharedPreferenceUtil; SharedPreferenceUtil sharedPreferenceUtil;
private CoordinatorLayout mainLayout;
private ZimManageActivity zimManageActivity; private ZimManageActivity zimManageActivity;
private Activity faActivity; private Activity activity;
private boolean hasArtificiallyPaused; private boolean hasArtificiallyPaused;
public static String toHumanReadableTime(int seconds) { static String toHumanReadableTime(int seconds) {
final double MINUTES = 60; final double MINUTES = 60;
final double HOURS = 60 * MINUTES; final double HOURS = 60 * MINUTES;
final double DAYS = 24 * HOURS; final double DAYS = 24 * HOURS;
@ -97,31 +97,32 @@ public class DownloadFragment extends BaseFragment {
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
faActivity = super.getActivity(); activity = getActivity();
relLayout = (RelativeLayout) inflater.inflate(R.layout.download_management, container, false); RelativeLayout relLayout =
(RelativeLayout) inflater.inflate(R.layout.download_management, container, false);
zimManageActivity = (ZimManageActivity) super.getActivity(); zimManageActivity = (ZimManageActivity) super.getActivity();
listView = relLayout.findViewById(R.id.zim_downloader_list); listView = relLayout.findViewById(R.id.zim_downloader_list);
downloadAdapter = new DownloadAdapter(mDownloads); downloadAdapter = new DownloadAdapter(downloads);
downloadAdapter.registerDataSetObserver(this); downloadAdapter.registerDataSetObserver(this);
listView.setAdapter(downloadAdapter); listView.setAdapter(downloadAdapter);
mainLayout = faActivity.findViewById(R.id.zim_manager_main_activity); mainLayout = activity.findViewById(R.id.zim_manager_main_activity);
return relLayout; return relLayout;
} }
@Override @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
updateNoDownloads(); updateNoDownloads();
} }
private void updateNoDownloads() { private void updateNoDownloads() {
if (faActivity == null) { if (activity == null) {
return; return;
} }
TextView noDownloadsText = faActivity.findViewById(R.id.download_management_no_downloads); TextView noDownloadsText = activity.findViewById(R.id.download_management_no_downloads);
if (noDownloadsText == null) return; if (noDownloadsText == null) return;
if (listView.getCount() == 0) { if (listView.getCount() == 0) {
noDownloadsText.setVisibility(View.VISIBLE); noDownloadsText.setVisibility(View.VISIBLE);
@ -136,7 +137,7 @@ public class DownloadFragment extends BaseFragment {
downloadAdapter.unRegisterDataSetObserver(); downloadAdapter.unRegisterDataSetObserver();
} }
public void showNoWiFiWarning(Context context, Runnable yesAction) { private void showNoWiFiWarning(Context context, Runnable yesAction) {
new AlertDialog.Builder(context) new AlertDialog.Builder(context)
.setTitle(R.string.wifi_only_title) .setTitle(R.string.wifi_only_title)
.setMessage(R.string.wifi_only_msg) .setMessage(R.string.wifi_only_msg)
@ -150,14 +151,14 @@ public class DownloadFragment extends BaseFragment {
.show(); .show();
} }
public void addDownload(int position, LibraryNetworkEntity.Book book, String fileName) { void addDownload(int position, LibraryNetworkEntity.Book book, String fileName) {
mDownloads.put(position, book); downloads.put(position, book);
mDownloadFiles.put(position, fileName); downloadFiles.put(position, fileName);
downloadAdapter.notifyDataSetChanged(); downloadAdapter.notifyDataSetChanged();
updateNoDownloads(); updateNoDownloads();
} }
public Bitmap StringToBitMap(String encodedString) { private Bitmap StringToBitMap(String encodedString) {
try { try {
byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT); byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length); return BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length);
@ -169,23 +170,23 @@ public class DownloadFragment extends BaseFragment {
public class DownloadAdapter extends BaseAdapter { public class DownloadAdapter extends BaseAdapter {
private LinkedHashMap<Integer, LibraryNetworkEntity.Book> mData = new LinkedHashMap<>(); private LinkedHashMap<Integer, LibraryNetworkEntity.Book> data;
private Integer[] mKeys; private Integer[] keys;
private DataSetObserver dataSetObserver; private DataSetObserver dataSetObserver;
public DownloadAdapter(LinkedHashMap<Integer, LibraryNetworkEntity.Book> data) { DownloadAdapter(LinkedHashMap<Integer, LibraryNetworkEntity.Book> data) {
mData = data; this.data = data;
mKeys = mData.keySet().toArray(new Integer[data.size()]); keys = this.data.keySet().toArray(new Integer[data.size()]);
} }
@Override @Override
public int getCount() { public int getCount() {
return mData.size(); return data.size();
} }
@Override @Override
public LibraryNetworkEntity.Book getItem(int position) { public LibraryNetworkEntity.Book getItem(int position) {
return mData.get(mKeys[position]); return data.get(keys[position]);
} }
@Override @Override
@ -193,22 +194,22 @@ public class DownloadFragment extends BaseFragment {
return arg0; return arg0;
} }
public void complete(int notificationID) { void complete(int notificationID) {
if (!isAdded()) { if (!isAdded()) {
return; return;
} }
int position = Arrays.asList(mKeys).indexOf(notificationID); int position = Arrays.asList(keys).indexOf(notificationID);
ViewGroup viewGroup = ViewGroup viewGroup =
(ViewGroup) listView.getChildAt(position - listView.getFirstVisiblePosition()); (ViewGroup) listView.getChildAt(position - listView.getFirstVisiblePosition());
if (viewGroup == null) { if (viewGroup == null) {
mDownloads.remove(mKeys[position]); downloads.remove(keys[position]);
mDownloadFiles.remove(mKeys[position]); downloadFiles.remove(keys[position]);
downloadAdapter.notifyDataSetChanged(); downloadAdapter.notifyDataSetChanged();
updateNoDownloads(); updateNoDownloads();
} }
ImageView pause = viewGroup.findViewById(R.id.pause); ImageView pause = viewGroup.findViewById(R.id.pause);
pause.setEnabled(false); pause.setEnabled(false);
String fileName = FileUtils.getFileName(mDownloadFiles.get(mKeys[position])); String fileName = FileUtils.getFileName(downloadFiles.get(keys[position]));
{ {
Snackbar completeSnack = Snackbar completeSnack =
Snackbar.make(mainLayout, getResources().getString(R.string.download_complete_snackbar), Snackbar.make(mainLayout, getResources().getString(R.string.download_complete_snackbar),
@ -221,15 +222,15 @@ public class DownloadFragment extends BaseFragment {
ZimFileSelectFragment zimFileSelectFragment = ZimFileSelectFragment zimFileSelectFragment =
(ZimFileSelectFragment) zimManageActivity.mSectionsPagerAdapter.getItem(0); (ZimFileSelectFragment) zimManageActivity.mSectionsPagerAdapter.getItem(0);
zimFileSelectFragment.addBook(fileName); zimFileSelectFragment.addBook(fileName);
mDownloads.remove(mKeys[position]); downloads.remove(keys[position]);
mDownloadFiles.remove(mKeys[position]); downloadFiles.remove(keys[position]);
downloadAdapter.notifyDataSetChanged(); downloadAdapter.notifyDataSetChanged();
updateNoDownloads(); updateNoDownloads();
} }
public void updateProgress(int progress, int notificationID) { void updateProgress(int progress, int notificationID) {
if (isAdded()) { if (isAdded()) {
int position = Arrays.asList(mKeys).indexOf(notificationID); int position = Arrays.asList(keys).indexOf(notificationID);
ViewGroup viewGroup = ViewGroup viewGroup =
(ViewGroup) listView.getChildAt(position - listView.getFirstVisiblePosition()); (ViewGroup) listView.getChildAt(position - listView.getFirstVisiblePosition());
if (viewGroup == null) { if (viewGroup == null) {
@ -238,7 +239,7 @@ public class DownloadFragment extends BaseFragment {
ProgressBar downloadProgress = viewGroup.findViewById(R.id.downloadProgress); ProgressBar downloadProgress = viewGroup.findViewById(R.id.downloadProgress);
downloadProgress.setProgress(progress); downloadProgress.setProgress(progress);
TextView timeRemaining = viewGroup.findViewById(R.id.time_remaining); TextView timeRemaining = viewGroup.findViewById(R.id.time_remaining);
int secLeft = LibraryFragment.mService.timeRemaining.get(mKeys[position], -1); int secLeft = LibraryFragment.downloadService.timeRemaining.get(keys[position], -1);
if (secLeft != -1) { if (secLeft != -1) {
timeRemaining.setText(toHumanReadableTime(secLeft)); timeRemaining.setText(toHumanReadableTime(secLeft));
} }
@ -247,14 +248,14 @@ public class DownloadFragment extends BaseFragment {
private void setPlayState(ImageView pauseButton, int position, int newPlayState) { private void setPlayState(ImageView pauseButton, int position, int newPlayState) {
if (newPlayState == DownloadService.PLAY) { //Playing if (newPlayState == DownloadService.PLAY) { //Playing
if (LibraryFragment.mService.playDownload(mKeys[position])) { if (LibraryFragment.downloadService.playDownload(keys[position])) {
pauseButton.setImageDrawable( pauseButton.setImageDrawable(
ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_24dp)); ContextCompat.getDrawable(activity, R.drawable.ic_pause_black_24dp));
} }
} else { //Pausing } else { //Pausing
LibraryFragment.mService.pauseDownload(mKeys[position]); LibraryFragment.downloadService.pauseDownload(keys[position]);
pauseButton.setImageDrawable( pauseButton.setImageDrawable(
ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_24dp)); ContextCompat.getDrawable(activity, R.drawable.ic_play_arrow_black_24dp));
} }
} }
@ -264,9 +265,9 @@ public class DownloadFragment extends BaseFragment {
// Check if an existing view is being reused, otherwise inflate the view // Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) { if (convertView == null) {
convertView = convertView =
LayoutInflater.from(faActivity).inflate(R.layout.download_item, parent, false); LayoutInflater.from(activity).inflate(R.layout.download_item, parent, false);
} }
mKeys = mData.keySet().toArray(new Integer[mData.size()]); keys = data.keySet().toArray(new Integer[0]);
// Lookup view for data population // Lookup view for data population
//downloadProgress.setProgress(download.progress); //downloadProgress.setProgress(download.progress);
// Populate the data into the template view using the data object // Populate the data into the template view using the data object
@ -281,34 +282,34 @@ public class DownloadFragment extends BaseFragment {
ProgressBar downloadProgress = convertView.findViewById(R.id.downloadProgress); ProgressBar downloadProgress = convertView.findViewById(R.id.downloadProgress);
ImageView pause = convertView.findViewById(R.id.pause); ImageView pause = convertView.findViewById(R.id.pause);
if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == 0) { if (LibraryFragment.downloadService.downloadStatus.get(keys[position]) == 0) {
downloadProgress.setProgress(0); downloadProgress.setProgress(0);
pause.setImageDrawable( pause.setImageDrawable(
ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_24dp)); ContextCompat.getDrawable(activity, R.drawable.ic_pause_black_24dp));
} else { } else {
downloadProgress.setProgress( downloadProgress.setProgress(
LibraryFragment.mService.downloadProgress.get(mKeys[position])); LibraryFragment.downloadService.downloadProgress.get(keys[position]));
if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PAUSE) { if (LibraryFragment.downloadService.downloadStatus.get(keys[position])
== DownloadService.PAUSE) {
pause.setImageDrawable( pause.setImageDrawable(
ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_24dp)); ContextCompat.getDrawable(activity, R.drawable.ic_play_arrow_black_24dp));
} }
if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PLAY) { if (LibraryFragment.downloadService.downloadStatus.get(keys[position])
== DownloadService.PLAY) {
pause.setImageDrawable( pause.setImageDrawable(
ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_24dp)); ContextCompat.getDrawable(activity, R.drawable.ic_pause_black_24dp));
} }
} }
pause.setOnClickListener(v -> { pause.setOnClickListener(v -> {
int newPlayPauseState = int newPlayPauseState =
LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PLAY LibraryFragment.downloadService.downloadStatus.get(keys[position])
? DownloadService.PAUSE : DownloadService.PLAY; == DownloadService.PLAY ? DownloadService.PAUSE : DownloadService.PLAY;
if (newPlayPauseState == DownloadService.PLAY if (newPlayPauseState == DownloadService.PLAY
&& MainActivity.wifiOnly && MainActivity.wifiOnly
&& !NetworkUtils.isWiFi(getContext())) { && !NetworkUtils.isWiFi(activity)) {
showNoWiFiWarning(getContext(), () -> { showNoWiFiWarning(getContext(), () -> setPlayState(pause, position, newPlayPauseState));
setPlayState(pause, position, newPlayPauseState);
});
return; return;
} }
@ -319,21 +320,21 @@ public class DownloadFragment extends BaseFragment {
ImageView stop = convertView.findViewById(R.id.stop); ImageView stop = convertView.findViewById(R.id.stop);
stop.setOnClickListener(v -> { stop.setOnClickListener(v -> {
hasArtificiallyPaused = hasArtificiallyPaused = LibraryFragment.downloadService.downloadStatus.get(keys[position])
LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PLAY; == DownloadService.PLAY;
setPlayState(pause, position, DownloadService.PAUSE); setPlayState(pause, position, DownloadService.PAUSE);
new AlertDialog.Builder(faActivity, dialogStyle()) new AlertDialog.Builder(activity, dialogStyle())
.setTitle(R.string.confirm_stop_download_title) .setTitle(R.string.confirm_stop_download_title)
.setMessage(R.string.confirm_stop_download_msg) .setMessage(R.string.confirm_stop_download_msg)
.setPositiveButton(R.string.yes, (dialog, i) -> { .setPositiveButton(R.string.yes, (dialog, i) -> {
LibraryFragment.mService.stopDownload(mKeys[position]); LibraryFragment.downloadService.stopDownload(keys[position]);
mDownloads.remove(mKeys[position]); downloads.remove(keys[position]);
mDownloadFiles.remove(mKeys[position]); downloadFiles.remove(keys[position]);
downloadAdapter.notifyDataSetChanged(); downloadAdapter.notifyDataSetChanged();
updateNoDownloads(); updateNoDownloads();
if (zimManageActivity.mSectionsPagerAdapter.libraryFragment.libraryAdapter != null) { if (zimManageActivity.mSectionsPagerAdapter.libraryFragment.libraryAdapter != null) {
zimManageActivity.mSectionsPagerAdapter.libraryFragment.libraryAdapter.getFilter() zimManageActivity.mSectionsPagerAdapter.libraryFragment.libraryAdapter.getFilter()
.filter(((ZimManageActivity) getActivity()).searchView.getQuery()); .filter(((ZimManageActivity) activity).searchView.getQuery());
} }
}) })
.setNegativeButton(R.string.no, (dialog, i) -> { .setNegativeButton(R.string.no, (dialog, i) -> {
@ -349,7 +350,7 @@ public class DownloadFragment extends BaseFragment {
return convertView; return convertView;
} }
public void registerDataSetObserver(DownloadFragment downloadFragment) { void registerDataSetObserver(DownloadFragment downloadFragment) {
if (dataSetObserver == null) { if (dataSetObserver == null) {
dataSetObserver = new DataSetObserver() { dataSetObserver = new DataSetObserver() {
@Override @Override
@ -369,7 +370,7 @@ public class DownloadFragment extends BaseFragment {
} }
} }
public void unRegisterDataSetObserver() { void unRegisterDataSetObserver() {
if (dataSetObserver != null) { if (dataSetObserver != null) {
unregisterDataSetObserver(dataSetObserver); unregisterDataSetObserver(dataSetObserver);
} }

View File

@ -231,9 +231,9 @@ public class DownloadService extends Service {
synchronized (pauseLock) { synchronized (pauseLock) {
pauseLock.notify(); pauseLock.notify();
} }
if (!DownloadFragment.mDownloads.isEmpty()) { if (!DownloadFragment.downloads.isEmpty()) {
DownloadFragment.mDownloads.remove(notificationID); DownloadFragment.downloads.remove(notificationID);
DownloadFragment.mDownloadFiles.remove(notificationID); DownloadFragment.downloadFiles.remove(notificationID);
DownloadFragment.downloadAdapter.notifyDataSetChanged(); DownloadFragment.downloadAdapter.notifyDataSetChanged();
} }
updateForeground(); updateForeground();
@ -428,10 +428,10 @@ public class DownloadService extends Service {
} }
private void updateDownloadFragmentProgress(int progress, int notificationID) { private void updateDownloadFragmentProgress(int progress, int notificationID) {
if (DownloadFragment.mDownloads != null if (DownloadFragment.downloads != null
&& DownloadFragment.mDownloads.get(notificationID) != null) { && DownloadFragment.downloads.get(notificationID) != null) {
handler.post(() -> { handler.post(() -> {
if (DownloadFragment.mDownloads.get(notificationID) != null) { if (DownloadFragment.downloads.get(notificationID) != null) {
DownloadFragment.downloadAdapter.updateProgress(progress, notificationID); DownloadFragment.downloadAdapter.updateProgress(progress, notificationID);
} }
}); });
@ -439,10 +439,10 @@ public class DownloadService extends Service {
} }
private void updateDownloadFragmentComplete(int notificationID) { private void updateDownloadFragmentComplete(int notificationID) {
if (DownloadFragment.mDownloads != null if (DownloadFragment.downloads != null
&& DownloadFragment.mDownloads.get(notificationID) != null) { && DownloadFragment.downloads.get(notificationID) != null) {
handler.post(() -> { handler.post(() -> {
if (DownloadFragment.mDownloads.get(notificationID) != null) { if (DownloadFragment.downloads.get(notificationID) != null) {
DownloadFragment.downloadAdapter.complete(notificationID); DownloadFragment.downloadAdapter.complete(notificationID);
} }
}); });
@ -526,8 +526,8 @@ public class DownloadService extends Service {
downloaded += output.length(); downloaded += output.length();
if (chunk.getStartByte() == 0) { if (chunk.getStartByte() == 0) {
if (!DownloadFragment.mDownloads.isEmpty()) { if (!DownloadFragment.downloads.isEmpty()) {
LibraryNetworkEntity.Book book = DownloadFragment.mDownloads LibraryNetworkEntity.Book book = DownloadFragment.downloads
.get(chunk.getNotificationID()); .get(chunk.getNotificationID());
book.remoteUrl = book.getUrl(); book.remoteUrl = book.getUrl();
book.file = fullFile; book.file = fullFile;

View File

@ -59,10 +59,11 @@ import static org.kiwix.kiwixmobile.utils.NetworkUtils.parseURL;
public class LibraryAdapter extends BaseAdapter { public class LibraryAdapter extends BaseAdapter {
private static final int LIST_ITEM_TYPE_BOOK = 0; private static final int LIST_ITEM_TYPE_BOOK = 0;
private static final int LIST_ITEM_TYPE_DIVIDER = 1; private static final int LIST_ITEM_TYPE_DIVIDER = 1;
public final HashMap<String, Integer> languageCounts = new HashMap<>();
private final Context context; private final Context context;
private final LayoutInflater layoutInflater; private final LayoutInflater layoutInflater;
private final BookFilter bookFilter = new BookFilter(); private final BookFilter bookFilter = new BookFilter();
public HashMap<String, Integer> languageCounts = new HashMap<>(); private final List<ListItem> listItems = new ArrayList<>();
public ArrayList<Language> languages = new ArrayList<>(); public ArrayList<Language> languages = new ArrayList<>();
@Inject BookUtils bookUtils; @Inject BookUtils bookUtils;
@Inject @Inject
@ -72,7 +73,6 @@ public class LibraryAdapter extends BaseAdapter {
@Inject @Inject
DataSource dataSource; DataSource dataSource;
private List<Book> allBooks; private List<Book> allBooks;
private List<ListItem> listItems = new ArrayList<>();
private Disposable saveNetworkLanguageDisposable; private Disposable saveNetworkLanguageDisposable;
public LibraryAdapter(Context context) { public LibraryAdapter(Context context) {
@ -355,7 +355,7 @@ public class LibraryAdapter extends BaseAdapter {
List<Book> selectedLanguages = Observable.fromIterable(allBooks) List<Book> selectedLanguages = Observable.fromIterable(allBooks)
.filter(LibraryAdapter.this::languageActive) .filter(LibraryAdapter.this::languageActive)
.filter(book -> !books.contains(book)) .filter(book -> !books.contains(book))
.filter(book -> !DownloadFragment.mDownloads.values().contains(book)) .filter(book -> !DownloadFragment.downloads.values().contains(book))
.filter(book -> !LibraryFragment.downloadingBooks.contains(book)) .filter(book -> !LibraryFragment.downloadingBooks.contains(book))
.filter(book -> !book.url.contains("/stack_exchange/")) // Temp filter see #694 .filter(book -> !book.url.contains("/stack_exchange/")) // Temp filter see #694
.toList() .toList()
@ -364,7 +364,7 @@ public class LibraryAdapter extends BaseAdapter {
List<Book> unselectedLanguages = Observable.fromIterable(allBooks) List<Book> unselectedLanguages = Observable.fromIterable(allBooks)
.filter(book -> !languageActive(book)) .filter(book -> !languageActive(book))
.filter(book -> !books.contains(book)) .filter(book -> !books.contains(book))
.filter(book -> !DownloadFragment.mDownloads.values().contains(book)) .filter(book -> !DownloadFragment.downloads.values().contains(book))
.filter(book -> !LibraryFragment.downloadingBooks.contains(book)) .filter(book -> !LibraryFragment.downloadingBooks.contains(book))
.filter(book -> !book.url.contains("/stack_exchange/")) // Temp filter see #694 .filter(book -> !book.url.contains("/stack_exchange/")) // Temp filter see #694
.toList() .toList()
@ -380,7 +380,7 @@ public class LibraryAdapter extends BaseAdapter {
List<Book> selectedLanguages = Observable.fromIterable(allBooks) List<Book> selectedLanguages = Observable.fromIterable(allBooks)
.filter(LibraryAdapter.this::languageActive) .filter(LibraryAdapter.this::languageActive)
.filter(book -> !books.contains(book)) .filter(book -> !books.contains(book))
.filter(book -> !DownloadFragment.mDownloads.values().contains(book)) .filter(book -> !DownloadFragment.downloads.values().contains(book))
.filter(book -> !LibraryFragment.downloadingBooks.contains(book)) .filter(book -> !LibraryFragment.downloadingBooks.contains(book))
.filter(book -> !book.url.contains("/stack_exchange/")) // Temp filter see #694 .filter(book -> !book.url.contains("/stack_exchange/")) // Temp filter see #694
.flatMap(book -> getMatches(book, s.toString())) .flatMap(book -> getMatches(book, s.toString()))
@ -392,7 +392,7 @@ public class LibraryAdapter extends BaseAdapter {
List<Book> unselectedLanguages = Observable.fromIterable(allBooks) List<Book> unselectedLanguages = Observable.fromIterable(allBooks)
.filter(book -> !languageActive(book)) .filter(book -> !languageActive(book))
.filter(book -> !books.contains(book)) .filter(book -> !books.contains(book))
.filter(book -> !DownloadFragment.mDownloads.values().contains(book)) .filter(book -> !DownloadFragment.downloads.values().contains(book))
.filter(book -> !LibraryFragment.downloadingBooks.contains(book)) .filter(book -> !LibraryFragment.downloadingBooks.contains(book))
.filter(book -> !book.url.contains("/stack_exchange/")) // Temp filter see #694 .filter(book -> !book.url.contains("/stack_exchange/")) // Temp filter see #694
.flatMap(book -> getMatches(book, s.toString())) .flatMap(book -> getMatches(book, s.toString()))
@ -415,7 +415,7 @@ public class LibraryAdapter extends BaseAdapter {
@Override @Override
protected void publishResults(CharSequence constraint, FilterResults results) { protected void publishResults(CharSequence constraint, FilterResults results) {
List<ListItem> filtered = (List<ListItem>) results.values; @SuppressWarnings("unchecked") List<ListItem> filtered = (List<ListItem>) results.values;
if (filtered != null) { if (filtered != null) {
if (filtered.isEmpty()) { if (filtered.isEmpty()) {
addBooks(allBooks); addBooks(allBooks);
@ -426,10 +426,10 @@ public class LibraryAdapter extends BaseAdapter {
} }
private class ListItem { private class ListItem {
public Object data; final Object data;
public int type; final int type;
public ListItem(Object data, int type) { ListItem(Object data, int type) {
this.data = data; this.data = data;
this.type = type; this.type = type;
} }

View File

@ -385,7 +385,7 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
} }
if (i.hasExtra(EXTRA_ZIM_FILE)) { if (i.hasExtra(EXTRA_ZIM_FILE)) {
File file = new File(FileUtils.getFileName(i.getStringExtra(EXTRA_ZIM_FILE))); File file = new File(FileUtils.getFileName(i.getStringExtra(EXTRA_ZIM_FILE)));
LibraryFragment.mService.cancelNotification(i.getIntExtra(EXTRA_NOTIFICATION_ID, 0)); LibraryFragment.downloadService.cancelNotification(i.getIntExtra(EXTRA_NOTIFICATION_ID, 0));
Uri uri = Uri.fromFile(file); Uri uri = Uri.fromFile(file);
finish(); finish();
@ -880,9 +880,9 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
case R.id.menu_support_kiwix: case R.id.menu_support_kiwix:
Uri uriSupportKiwix = Uri.parse("https://www.kiwix.org/support"); Uri uriSupportKiwix = Uri.parse("https://www.kiwix.org/support");
Intent intertSupportKiwix = new Intent(Intent.ACTION_VIEW, uriSupportKiwix); Intent intentSupportKiwix = new Intent(Intent.ACTION_VIEW, uriSupportKiwix);
intertSupportKiwix.putExtra(EXTRA_EXTERNAL_LINK, true); intentSupportKiwix.putExtra(EXTRA_EXTERNAL_LINK, true);
openExternalUrl(intertSupportKiwix); openExternalUrl(intentSupportKiwix);
default: default:
break; break;

View File

@ -82,7 +82,7 @@ public class LibraryFragment extends BaseFragment
new CountingIdlingResource("Library Fragment Idling Resource"); new CountingIdlingResource("Library Fragment Idling Resource");
public static final List<Book> downloadingBooks = new ArrayList<>(); public static final List<Book> downloadingBooks = new ArrayList<>();
private static final String EXTRA_BOOKS_ONLINE = "books_online"; private static final String EXTRA_BOOKS_ONLINE = "books_online";
public static DownloadService mService = new DownloadService(); public static DownloadService downloadService = new DownloadService();
private static NetworkBroadcastReceiver networkBroadcastReceiver; private static NetworkBroadcastReceiver networkBroadcastReceiver;
private static boolean isReceiverRegistered = false; private static boolean isReceiverRegistered = false;
public LibraryAdapter libraryAdapter; public LibraryAdapter libraryAdapter;
@ -95,14 +95,14 @@ public class LibraryFragment extends BaseFragment
@BindView(R.id.library_swiperefresh) @BindView(R.id.library_swiperefresh)
SwipeRefreshLayout swipeRefreshLayout; SwipeRefreshLayout swipeRefreshLayout;
@Inject @Inject
ConnectivityManager conMan; ConnectivityManager connectivityManager;
@Inject @Inject
LibraryPresenter presenter; LibraryPresenter presenter;
@Inject @Inject
SharedPreferenceUtil sharedPreferenceUtil; SharedPreferenceUtil sharedPreferenceUtil;
private LinkedList<Book> books; private LinkedList<Book> books;
private boolean mBound; private boolean bound;
private DownloadServiceConnection mConnection = new DownloadServiceConnection(); private DownloadServiceConnection downloadServiceConnection = new DownloadServiceConnection();
private ZimManageActivity activity; private ZimManageActivity activity;
@Override @Override
@ -124,7 +124,7 @@ public class LibraryFragment extends BaseFragment
DownloadService.setDownloadFragment(activity.mSectionsPagerAdapter.getDownloadFragment()); DownloadService.setDownloadFragment(activity.mSectionsPagerAdapter.getDownloadFragment());
NetworkInfo network = conMan.getActiveNetworkInfo(); NetworkInfo network = connectivityManager.getActiveNetworkInfo();
if (network == null || !network.isConnected()) { if (network == null || !network.isConnected()) {
displayNoNetworkConnection(); displayNoNetworkConnection();
} }
@ -218,7 +218,7 @@ public class LibraryFragment extends BaseFragment
} }
private void refreshFragment() { private void refreshFragment() {
NetworkInfo network = conMan.getActiveNetworkInfo(); NetworkInfo network = connectivityManager.getActiveNetworkInfo();
if (network == null || !network.isConnected()) { if (network == null || !network.isConnected()) {
Toast.makeText(super.getActivity(), R.string.no_network_connection, Toast.LENGTH_LONG).show(); Toast.makeText(super.getActivity(), R.string.no_network_connection, Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
@ -231,9 +231,9 @@ public class LibraryFragment extends BaseFragment
public void onDestroyView() { public void onDestroyView() {
presenter.detachView(); presenter.detachView();
super.onDestroyView(); super.onDestroyView();
if (mBound && super.getActivity() != null) { if (bound && super.getActivity() != null) {
super.getActivity().unbindService(mConnection.downloadServiceInterface); super.getActivity().unbindService(downloadServiceConnection.downloadServiceInterface);
mBound = false; bound = false;
} }
} }
@ -266,7 +266,7 @@ public class LibraryFragment extends BaseFragment
return; return;
} }
if (DownloadFragment.mDownloadFiles if (DownloadFragment.downloadFiles
.containsValue(KIWIX_ROOT + StorageUtils.getFileNameFromUrl(((Book) parent.getAdapter() .containsValue(KIWIX_ROOT + StorageUtils.getFileNameFromUrl(((Book) parent.getAdapter()
.getItem(position)).getUrl()))) { .getItem(position)).getUrl()))) {
Toast.makeText(super.getActivity(), getString(R.string.zim_already_downloading), Toast.makeText(super.getActivity(), getString(R.string.zim_already_downloading),
@ -274,7 +274,7 @@ public class LibraryFragment extends BaseFragment
.show(); .show();
} else { } else {
NetworkInfo network = conMan.getActiveNetworkInfo(); NetworkInfo network = connectivityManager.getActiveNetworkInfo();
if (network == null || !network.isConnected()) { if (network == null || !network.isConnected()) {
Toast.makeText(super.getActivity(), getString(R.string.no_network_connection), Toast.makeText(super.getActivity(), getString(R.string.no_network_connection),
Toast.LENGTH_LONG) Toast.LENGTH_LONG)
@ -315,8 +315,9 @@ public class LibraryFragment extends BaseFragment
service.putExtra(DownloadIntent.DOWNLOAD_ZIM_TITLE, book.getTitle()); service.putExtra(DownloadIntent.DOWNLOAD_ZIM_TITLE, book.getTitle());
service.putExtra(EXTRA_BOOK, book); service.putExtra(EXTRA_BOOK, book);
activity.startService(service); activity.startService(service);
mConnection = new DownloadServiceConnection(); downloadServiceConnection = new DownloadServiceConnection();
activity.bindService(service, mConnection.downloadServiceInterface, Context.BIND_AUTO_CREATE); activity.bindService(service, downloadServiceConnection.downloadServiceInterface,
Context.BIND_AUTO_CREATE);
activity.displayDownloadInterface(); activity.displayDownloadInterface();
} }
@ -363,8 +364,8 @@ public class LibraryFragment extends BaseFragment
public void onServiceConnected(ComponentName className, IBinder service) { public void onServiceConnected(ComponentName className, IBinder service) {
// We've bound to LocalService, cast the IBinder and get LocalService instance // We've bound to LocalService, cast the IBinder and get LocalService instance
DownloadService.LocalBinder binder = (DownloadService.LocalBinder) service; DownloadService.LocalBinder binder = (DownloadService.LocalBinder) service;
mService = binder.getService(); downloadService = binder.getService();
mBound = true; bound = true;
} }
@Override @Override
@ -376,7 +377,7 @@ public class LibraryFragment extends BaseFragment
public class NetworkBroadcastReceiver extends BroadcastReceiver { public class NetworkBroadcastReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
NetworkInfo network = conMan.getActiveNetworkInfo(); NetworkInfo network = connectivityManager.getActiveNetworkInfo();
if (network == null || !network.isConnected()) { if (network == null || !network.isConnected()) {
displayNoNetworkConnection(); displayNoNetworkConnection();
@ -388,8 +389,6 @@ public class LibraryFragment extends BaseFragment
permissionButton.setVisibility(GONE); permissionButton.setVisibility(GONE);
networkText.setVisibility(GONE); networkText.setVisibility(GONE);
libraryList.setVisibility(View.VISIBLE); libraryList.setVisibility(View.VISIBLE);
} else {
stopScanningContent();
} }
} }
} }

View File

@ -54,7 +54,7 @@ public class LibraryPresenter extends BasePresenter<LibraryViewCallback> {
void loadRunningDownloadsFromDb() { void loadRunningDownloadsFromDb() {
for (LibraryNetworkEntity.Book book : bookDao.getDownloadingBooks()) { for (LibraryNetworkEntity.Book book : bookDao.getDownloadingBooks()) {
if (!DownloadFragment.mDownloads.containsValue(book)) { if (!DownloadFragment.downloads.containsValue(book)) {
book.url = book.remoteUrl; book.url = book.remoteUrl;
view.downloadFile(book); view.downloadFile(book);
} }