reduced potential memory leaks

This commit is contained in:
Elad Keyshawn 2016-12-29 17:12:56 +02:00
parent 185e0c2a08
commit 773cc45dcd
4 changed files with 19 additions and 10 deletions

View File

@ -75,6 +75,7 @@ public class LibraryFragment extends Fragment implements AdapterView.OnItemClick
private ZimManageActivity faActivity;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
faActivity = (ZimManageActivity) super.getActivity();
@ -86,7 +87,7 @@ public class LibraryFragment extends Fragment implements AdapterView.OnItemClick
// Don't use this method, it's handled by inflater.inflate() above :
// setContentView(R.layout.activity_layout);
ButterKnife.bind(this, llLayout);
mService.setDownloadFragment(faActivity.mSectionsPagerAdapter.getDownloadFragment());
kiwixService = ((KiwixApplication) super.getActivity().getApplication()).getKiwixService();
conMan = (ConnectivityManager) super.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo network = conMan.getActiveNetworkInfo();

View File

@ -244,6 +244,10 @@ public class ZimManageActivity extends AppCompatActivity {
private DownloadFragment downloadFragment = new DownloadFragment();
public DownloadFragment getDownloadFragment() {
return downloadFragment;
}
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}

View File

@ -33,11 +33,11 @@ public class DownloadFragment extends Fragment {
public static LinkedHashMap<Integer, LibraryNetworkEntity.Book> mDownloads = new LinkedHashMap<>();
public static LinkedHashMap<Integer, String> mDownloadFiles = new LinkedHashMap<>();
public RelativeLayout relLayout;
public static ListView listView;
public ListView listView;
public static DownloadAdapter downloadAdapter;
private ZimManageActivity zimManageActivity;
CoordinatorLayout mainLayout;
private static FragmentActivity faActivity;
private FragmentActivity faActivity;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -58,7 +58,7 @@ public class DownloadFragment extends Fragment {
updateNoDownloads();
}
private static void updateNoDownloads() {
private void updateNoDownloads() {
TextView noDownloadsText = (TextView) faActivity.findViewById(R.id.download_management_no_downloads);
if (noDownloadsText == null) return;
if (listView.getCount() == 0) {
@ -204,7 +204,7 @@ public class DownloadFragment extends Fragment {
}
public static void addDownload(int position, LibraryNetworkEntity.Book book, String fileName) {
public void addDownload(int position, LibraryNetworkEntity.Book book, String fileName) {
mDownloads.put(position, book);
mDownloadFiles.put(position, fileName);
downloadAdapter.notifyDataSetChanged();

View File

@ -61,17 +61,21 @@ public class DownloadService extends Service {
private static String SD_CARD;
public static String KIWIX_ROOT;
public static int notificationCount = 1;
public static ArrayList<String> notifications = new ArrayList<String>();
public static ArrayList<String> notifications = new ArrayList<>();
public String notificationTitle;
private HashMap<Integer, NotificationCompat.Builder> notification = new HashMap<>();
private NotificationManager notificationManager;
public HashMap<Integer, Integer> downloadStatus = new HashMap<Integer, Integer>();
public HashMap<Integer, Integer> downloadProgress = new HashMap<Integer, Integer>();
public HashMap<Integer, Integer> downloadStatus = new HashMap<>();
public HashMap<Integer, Integer> downloadProgress = new HashMap<>();
public static Object pauseLock = new Object();
public static BookDao bookDao;
private static DownloadFragment downloadFragment;
Handler handler = new Handler(Looper.getMainLooper());
public static void setDownloadFragment(DownloadFragment dFragment) {
downloadFragment = dFragment;
}
@Override
public void onCreate() {
kiwixService = ((KiwixApplication) getApplication()).getKiwixService();
@ -158,7 +162,7 @@ public class DownloadService extends Service {
}
private void downloadBook(String url, int notificationID, LibraryNetworkEntity.Book book) {
DownloadFragment.addDownload(notificationID, book, KIWIX_ROOT + StorageUtils.getFileNameFromUrl(book.getUrl()));
downloadFragment.addDownload(notificationID, book, KIWIX_ROOT + StorageUtils.getFileNameFromUrl(book.getUrl()));
kiwixService.getMetaLinks(url)
.subscribeOn(AndroidSchedulers.mainThread())
.flatMap(metaLink -> getMetaLinkContentLength(metaLink.getRelevantUrl().getValue()))