Merge pull request #90 from kiwix/elad/etc

cleanup and structure changes
This commit is contained in:
Elad Keyshawn 2017-04-07 22:35:49 +02:00 committed by GitHub
commit 901d24c393
19 changed files with 47 additions and 90 deletions

View File

@ -146,7 +146,7 @@
<activity android:name=".settings.KiwixSettingsActivity" />
<activity android:name=".SearchActivity" />
<activity android:name=".bookmarksView.BookmarksActivity" />
<activity android:name=".bookmarks_view.BookmarksActivity" />
<provider
android:name=".ZimContentProvider"

View File

@ -1,38 +0,0 @@
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");
}
}
}

View File

@ -82,7 +82,8 @@ import java.util.Locale;
import javax.inject.Inject;
import okhttp3.OkHttpClient;
import org.json.JSONArray;
import org.kiwix.kiwixmobile.bookmarksView.BookmarksActivity;
import org.kiwix.kiwixmobile.base.BaseActivity;
import org.kiwix.kiwixmobile.bookmarks_view.BookmarksActivity;
import org.kiwix.kiwixmobile.database.BookmarksDao;
import org.kiwix.kiwixmobile.database.KiwixDatabase;
import org.kiwix.kiwixmobile.di.components.ApplicationComponent;

View File

@ -1,12 +0,0 @@
package org.kiwix.kiwixmobile;
/**
* Created by EladKeyshawn on 06/04/2017.
*/
public interface Presenter<V extends ViewCallback> {
void attachView(V viewCallback);
void detachView();
}

View File

@ -1,8 +0,0 @@
package org.kiwix.kiwixmobile;
/**
* Created by EladKeyshawn on 06/04/2017.
*/
public interface ViewCallback {
}

View File

@ -1,8 +1,10 @@
package org.kiwix.kiwixmobile;
package org.kiwix.kiwixmobile.base;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import org.kiwix.kiwixmobile.KiwixApplication;
import org.kiwix.kiwixmobile.di.components.ApplicationComponent;
public abstract class BaseActivity extends AppCompatActivity {

View File

@ -1,4 +1,4 @@
package org.kiwix.kiwixmobile.bookmarksView;
package org.kiwix.kiwixmobile.base;
/**
* Created by EladKeyshawn on 05/04/2017.

View File

@ -1,4 +1,6 @@
package org.kiwix.kiwixmobile.bookmarksView;
package org.kiwix.kiwixmobile.base;
import org.kiwix.kiwixmobile.base.ViewCallback;
/**
* Created by EladKeyshawn on 05/04/2017.

View File

@ -1,4 +1,4 @@
package org.kiwix.kiwixmobile.bookmarksView;
package org.kiwix.kiwixmobile.base;
/**
* Created by EladKeyshawn on 05/04/2017.

View File

@ -18,7 +18,7 @@
*/
package org.kiwix.kiwixmobile.bookmarksView;
package org.kiwix.kiwixmobile.bookmarks_view;
import android.content.Context;
import android.content.Intent;
@ -44,7 +44,7 @@ import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import org.kiwix.kiwixmobile.BaseActivity;
import org.kiwix.kiwixmobile.base.BaseActivity;
import org.kiwix.kiwixmobile.KiwixMobileActivity;
import org.kiwix.kiwixmobile.R;
import org.kiwix.kiwixmobile.di.components.ApplicationComponent;

View File

@ -1,8 +1,9 @@
package org.kiwix.kiwixmobile.bookmarksView;
package org.kiwix.kiwixmobile.bookmarks_view;
import android.content.Context;
import org.kiwix.kiwixmobile.ZimContentProvider;
import org.kiwix.kiwixmobile.base.BasePresenter;
import org.kiwix.kiwixmobile.database.BookmarksDao;
import org.kiwix.kiwixmobile.database.KiwixDatabase;

View File

@ -1,4 +1,6 @@
package org.kiwix.kiwixmobile.bookmarksView;
package org.kiwix.kiwixmobile.bookmarks_view;
import org.kiwix.kiwixmobile.base.ViewCallback;
import java.util.ArrayList;

View File

@ -6,7 +6,7 @@ import javax.inject.Singleton;
import org.kiwix.kiwixmobile.KiwixMobileActivity;
import org.kiwix.kiwixmobile.zim_manager.fileselect_view.ZimFileSelectFragment;
import org.kiwix.kiwixmobile.bookmarksView.BookmarksActivity;
import org.kiwix.kiwixmobile.bookmarks_view.BookmarksActivity;
import org.kiwix.kiwixmobile.di.modules.ApplicationModule;
import org.kiwix.kiwixmobile.di.modules.NetworkModule;
import org.kiwix.kiwixmobile.downloader.DownloadService;

View File

@ -16,13 +16,6 @@ import rx.schedulers.Schedulers;
}
@Provides @Singleton KiwixService provideKiwixService(OkHttpClient okHttpClient) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://download.kiwix.org/")
.client(okHttpClient)
.addConverterFactory(SimpleXmlConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
.build();
return retrofit.create(KiwixService.class);
return KiwixService.ServiceCreator.newHacklistService(okHttpClient);
}
}

View File

@ -2,12 +2,34 @@ package org.kiwix.kiwixmobile.network;
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
import org.kiwix.kiwixmobile.library.entity.MetaLinkNetworkEntity;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Url;
import rx.Observable;
import rx.schedulers.Schedulers;
public interface KiwixService {
@GET("/library/library.xml") Observable<LibraryNetworkEntity> getLibrary();
@GET Observable<MetaLinkNetworkEntity> getMetaLinks(@Url String url);
/******** Helper class that sets up new services *******/
class ServiceCreator {
public static KiwixService newHacklistService(OkHttpClient okHttpClient) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://download.kiwix.org/")
.client(okHttpClient)
.addConverterFactory(SimpleXmlConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
.build();
return retrofit.create(KiwixService.class);
}
}
}

View File

@ -1,24 +1,16 @@
package org.kiwix.kiwixmobile.zim_manager.fileselect_view;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import org.kiwix.kiwixmobile.BasePresenter;
import org.kiwix.kiwixmobile.base.BasePresenter;
import org.kiwix.kiwixmobile.database.BookDao;
import org.kiwix.kiwixmobile.database.KiwixDatabase;
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
import org.kiwix.kiwixmobile.utils.files.FileSearch;
import org.kiwix.kiwixmobile.zim_manager.ZimManageActivity;
import org.kiwix.kiwixmobile.zim_manager.library_view.LibraryFragment;
import java.util.ArrayList;
import javax.inject.Inject;
import static org.kiwix.kiwixmobile.R.id.progressBar;
import static org.kiwix.kiwixmobile.downloader.DownloadService.bookDao;
/**
* Created by EladKeyshawn on 06/04/2017.
*/

View File

@ -1,6 +1,6 @@
package org.kiwix.kiwixmobile.zim_manager.fileselect_view;
import org.kiwix.kiwixmobile.ViewCallback;
import org.kiwix.kiwixmobile.base.ViewCallback;
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
import java.util.ArrayList;
@ -8,7 +8,7 @@ import java.util.ArrayList;
/**
* Created by EladKeyshawn on 06/04/2017.
*/
public interface ZimFileSelectViewCallback extends ViewCallback{
public interface ZimFileSelectViewCallback extends ViewCallback {
void showFiles(ArrayList<LibraryNetworkEntity.Book> books);
void updateFilesAdapter();

View File

@ -2,7 +2,7 @@ package org.kiwix.kiwixmobile.zim_manager.library_view;
import android.content.Context;
import org.kiwix.kiwixmobile.BasePresenter;
import org.kiwix.kiwixmobile.base.BasePresenter;
import org.kiwix.kiwixmobile.database.BookDao;
import org.kiwix.kiwixmobile.database.KiwixDatabase;
import org.kiwix.kiwixmobile.downloader.DownloadFragment;

View File

@ -1,6 +1,6 @@
package org.kiwix.kiwixmobile.zim_manager.library_view;
import org.kiwix.kiwixmobile.ViewCallback;
import org.kiwix.kiwixmobile.base.ViewCallback;
import org.kiwix.kiwixmobile.library.entity.LibraryNetworkEntity;
import java.util.LinkedList;