mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-18 11:55:38 -04:00
- moved library to dedicated folder
- getLibraryData now in presenter
This commit is contained in:
parent
53bfd184f3
commit
160f05f6ca
@ -122,7 +122,7 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ZimManageActivity"
|
||||
android:name=".zim_manager.ZimManageActivity"
|
||||
android:label="@string/choose_file">
|
||||
|
||||
<!-- TODO -->
|
||||
|
38
app/src/main/java/org/kiwix/kiwixmobile/BasePresenter.java
Normal file
38
app/src/main/java/org/kiwix/kiwixmobile/BasePresenter.java
Normal file
@ -0,0 +1,38 @@
|
||||
package org.kiwix.kiwixmobile;
|
||||
|
||||
/**
|
||||
* Created by EladKeyshawn on 06/04/2017.
|
||||
*/
|
||||
public class BasePresenter<T extends ViewCallback> implements Presenter<T> {
|
||||
|
||||
private T mMvpView;
|
||||
|
||||
@Override
|
||||
public void attachView(T mvpView) {
|
||||
mMvpView = mvpView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
mMvpView = null;
|
||||
}
|
||||
|
||||
public boolean isViewAttached() {
|
||||
return mMvpView != null;
|
||||
}
|
||||
|
||||
public T getMvpView() {
|
||||
return mMvpView;
|
||||
}
|
||||
|
||||
public void checkViewAttached() {
|
||||
if (!isViewAttached()) throw new MvpViewNotAttachedException();
|
||||
}
|
||||
|
||||
public static class MvpViewNotAttachedException extends RuntimeException {
|
||||
public MvpViewNotAttachedException() {
|
||||
super("Please call Presenter.attachView(MvpView) before" +
|
||||
" requesting data to the Presenter");
|
||||
}
|
||||
}
|
||||
}
|
@ -102,6 +102,8 @@ import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback;
|
||||
import org.kiwix.kiwixmobile.views.web.KiwixWebView;
|
||||
import org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView;
|
||||
import org.kiwix.kiwixmobile.views.web.ToolbarStaticKiwixWebView;
|
||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
|
||||
|
||||
import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
|
||||
import static org.kiwix.kiwixmobile.TableDrawerAdapter.DocumentSection;
|
||||
|
12
app/src/main/java/org/kiwix/kiwixmobile/Presenter.java
Normal file
12
app/src/main/java/org/kiwix/kiwixmobile/Presenter.java
Normal file
@ -0,0 +1,12 @@
|
||||
package org.kiwix.kiwixmobile;
|
||||
|
||||
/**
|
||||
* Created by EladKeyshawn on 06/04/2017.
|
||||
*/
|
||||
|
||||
public interface Presenter<V extends ViewCallback> {
|
||||
|
||||
void attachView(V viewCallback);
|
||||
|
||||
void detachView();
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package org.kiwix.kiwixmobile;
|
||||
|
||||
/**
|
||||
* Created by EladKeyshawn on 06/04/2017.
|
||||
*/
|
||||
|
||||
public interface ViewCallback {
|
||||
}
|
@ -55,6 +55,8 @@ import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
|
||||
import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
||||
import org.kiwix.kiwixmobile.utils.files.FileSearch;
|
||||
import org.kiwix.kiwixmobile.utils.files.FileUtils;
|
||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
|
||||
|
||||
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
||||
|
||||
|
@ -3,10 +3,10 @@ package org.kiwix.kiwixmobile.di.components;
|
||||
import dagger.Component;
|
||||
import javax.inject.Singleton;
|
||||
import org.kiwix.kiwixmobile.KiwixMobileActivity;
|
||||
import org.kiwix.kiwixmobile.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.di.modules.ApplicationModule;
|
||||
import org.kiwix.kiwixmobile.di.modules.NetworkModule;
|
||||
import org.kiwix.kiwixmobile.downloader.DownloadService;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
@ -19,4 +19,5 @@ public interface ApplicationComponent {
|
||||
void inject(DownloadService service);
|
||||
|
||||
void inject(LibraryFragment libraryFragment);
|
||||
|
||||
}
|
||||
|
@ -25,10 +25,10 @@ import android.widget.TextView;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.kiwix.kiwixmobile.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.ZimFileSelectFragment;
|
||||
import org.kiwix.kiwixmobile.ZimManageActivity;
|
||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity;
|
||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
|
||||
import org.kiwix.kiwixmobile.utils.files.FileUtils;
|
||||
|
||||
|
@ -28,7 +28,7 @@ import okhttp3.Response;
|
||||
import okio.BufferedSource;
|
||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
||||
import org.kiwix.kiwixmobile.KiwixMobileActivity;
|
||||
import org.kiwix.kiwixmobile.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.database.BookDao;
|
||||
import org.kiwix.kiwixmobile.database.KiwixDatabase;
|
||||
|
@ -38,22 +38,17 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.kiwix.kiwixmobile.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.ZimManageActivity;
|
||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity;
|
||||
import org.kiwix.kiwixmobile.database.BookDao;
|
||||
import org.kiwix.kiwixmobile.database.KiwixDatabase;
|
||||
import org.kiwix.kiwixmobile.database.NetworkLanguageDao;
|
||||
import org.kiwix.kiwixmobile.downloader.DownloadFragment;
|
||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
|
||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity.Book;
|
||||
import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
||||
|
||||
|
@ -45,11 +45,10 @@ import eu.mhutti1.utils.storage.StorageSelectDialog;
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
import org.kiwix.kiwixmobile.KiwixMobileActivity;
|
||||
import org.kiwix.kiwixmobile.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.database.KiwixDatabase;
|
||||
import org.kiwix.kiwixmobile.database.RecentSearchDao;
|
||||
import org.kiwix.kiwixmobile.utils.DimenUtils;
|
||||
import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
||||
import org.kiwix.kiwixmobile.utils.StyleUtils;
|
||||
import org.kiwix.kiwixmobile.views.SliderPreference;
|
||||
|
@ -2,14 +2,9 @@ package org.kiwix.kiwixmobile.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.TypedValue;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import org.kiwix.kiwixmobile.ZimManageActivity;
|
||||
|
||||
/**
|
||||
* Created by gmon on 1/13/17.
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.kiwix.kiwixmobile;
|
||||
package org.kiwix.kiwixmobile.zim_manager;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -24,13 +24,16 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.kiwix.kiwixmobile.KiwixMobileActivity;
|
||||
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.ZimFileSelectFragment;
|
||||
import org.kiwix.kiwixmobile.downloader.DownloadFragment;
|
||||
import org.kiwix.kiwixmobile.library.LibraryAdapter;
|
||||
import org.kiwix.kiwixmobile.utils.DimenUtils;
|
||||
|
||||
import static org.kiwix.kiwixmobile.utils.StyleUtils.dialogStyle;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.kiwix.kiwixmobile;
|
||||
package org.kiwix.kiwixmobile.zim_manager.library_view;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentManager;
|
||||
@ -42,6 +42,10 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.kiwix.kiwixmobile.KiwixApplication;
|
||||
import org.kiwix.kiwixmobile.KiwixMobileActivity;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.database.BookDao;
|
||||
import org.kiwix.kiwixmobile.database.KiwixDatabase;
|
||||
import org.kiwix.kiwixmobile.downloader.DownloadFragment;
|
||||
@ -52,6 +56,8 @@ import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
|
||||
import org.kiwix.kiwixmobile.network.KiwixService;
|
||||
import org.kiwix.kiwixmobile.utils.StorageUtils;
|
||||
import org.kiwix.kiwixmobile.utils.StyleUtils;
|
||||
import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity;
|
||||
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
|
||||
import static org.kiwix.kiwixmobile.downloader.DownloadService.KIWIX_ROOT;
|
@ -0,0 +1,45 @@
|
||||
package org.kiwix.kiwixmobile.zim_manager.library_view;
|
||||
|
||||
import org.kiwix.kiwixmobile.BasePresenter;
|
||||
import org.kiwix.kiwixmobile.network.KiwixService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
|
||||
/**
|
||||
* Created by EladKeyshawn on 06/04/2017.
|
||||
*/
|
||||
|
||||
public class LibraryPresenter extends BasePresenter<LibraryViewCallback> {
|
||||
|
||||
@Inject KiwixService kiwixService;
|
||||
|
||||
@Inject
|
||||
public LibraryPresenter() {
|
||||
}
|
||||
|
||||
|
||||
void loadBooks() {
|
||||
getMvpView().displayScanningContent();
|
||||
kiwixService.getLibrary()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(library -> {
|
||||
getMvpView().showBooks(library.getBooks());
|
||||
}, error -> {
|
||||
getMvpView().displayNoNetworkConnection();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(LibraryViewCallback view) {
|
||||
super.attachView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
super.detachView();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.kiwix.kiwixmobile.zim_manager.library_view;
|
||||
|
||||
import org.kiwix.kiwixmobile.ViewCallback;
|
||||
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* Created by EladKeyshawn on 06/04/2017.
|
||||
*/
|
||||
|
||||
public interface LibraryViewCallback extends ViewCallback {
|
||||
|
||||
void showBooks(LinkedList<LibraryNetworkEntity.Book> books);
|
||||
|
||||
|
||||
void displayNoNetworkConnection();
|
||||
|
||||
void displayScanningContent();
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package org.kiwix.kiwixmobile.zim_manager.library_view;
|
||||
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.MathContext;
|
||||
|
||||
/**
|
||||
* Created by EladKeyshawn on 06/04/2017.
|
||||
*/
|
||||
|
||||
public class UtilFunctions {
|
||||
public static String bytesToHuman(long size) {
|
||||
long KB = 1024;
|
||||
long MB = KB * 1024;
|
||||
long GB = MB * 1024;
|
||||
long TB = GB * 1024;
|
||||
long PB = TB * 1024;
|
||||
long EB = PB * 1024;
|
||||
|
||||
if (size < KB) { return size + " Bytes"; }
|
||||
if (size >= KB && size < MB) { return round3SF((double) size / KB) + " KB"; }
|
||||
if (size >= MB && size < GB) { return round3SF((double) size / MB) + " MB"; }
|
||||
if (size >= GB && size < TB) { return round3SF((double) size / GB) + " GB"; }
|
||||
if (size >= TB && size < PB) { return round3SF((double) size / TB) + " TB"; }
|
||||
if (size >= PB && size < EB) { return round3SF((double) size / PB) + " PB"; }
|
||||
if (size >= EB) { return round3SF((double) size / EB) + " EB"; }
|
||||
|
||||
return "???";
|
||||
}
|
||||
|
||||
|
||||
public static String round3SF(double size) {
|
||||
BigDecimal bd = new BigDecimal(size);
|
||||
bd = bd.round(new MathContext(3));
|
||||
return String.valueOf(bd.doubleValue());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".LibraryFragment">
|
||||
tools:context=".zim_manager.library_view.LibraryFragment">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -6,7 +6,7 @@
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".ZimManageActivity$PlaceholderFragment">
|
||||
tools:context=".zim_manager.ZimManageActivity$PlaceholderFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/section_label"
|
||||
|
@ -6,7 +6,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context=".ZimManageActivity">
|
||||
tools:context=".zim_manager.ZimManageActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
|
Loading…
x
Reference in New Issue
Block a user