mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2025-01-31 18:02:46 +01:00
Implementation of a new Dagger injection (#103)
This commit is contained in:
parent
b59008a90f
commit
3f1fff6d96
@ -1,7 +1,5 @@
|
||||
package io.github.wulkanowy;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.crashlytics.android.answers.Answers;
|
||||
import com.crashlytics.android.core.CrashlyticsCore;
|
||||
@ -11,18 +9,16 @@ import org.greenrobot.greendao.query.QueryBuilder;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.AndroidInjector;
|
||||
import dagger.android.support.DaggerApplication;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import eu.davidea.flexibleadapter.utils.Log;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.di.component.ApplicationComponent;
|
||||
import io.github.wulkanowy.di.component.DaggerApplicationComponent;
|
||||
import io.github.wulkanowy.di.modules.ApplicationModule;
|
||||
import io.github.wulkanowy.di.DaggerAppComponent;
|
||||
import io.github.wulkanowy.utils.LogUtils;
|
||||
|
||||
public class WulkanowyApp extends Application {
|
||||
|
||||
protected ApplicationComponent applicationComponent;
|
||||
public class WulkanowyApp extends DaggerApplication {
|
||||
|
||||
@Inject
|
||||
RepositoryContract repository;
|
||||
@ -32,12 +28,6 @@ public class WulkanowyApp extends Application {
|
||||
super.onCreate();
|
||||
AndroidThreeTen.init(this);
|
||||
|
||||
applicationComponent = DaggerApplicationComponent
|
||||
.builder()
|
||||
.applicationModule(new ApplicationModule(this))
|
||||
.build();
|
||||
applicationComponent.inject(this);
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
enableDebugLog();
|
||||
}
|
||||
@ -72,7 +62,8 @@ public class WulkanowyApp extends Application {
|
||||
.build());
|
||||
}
|
||||
|
||||
public ApplicationComponent getApplicationComponent() {
|
||||
return applicationComponent;
|
||||
@Override
|
||||
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
|
||||
return DaggerAppComponent.builder().create(this);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
@ -21,8 +22,6 @@ import io.github.wulkanowy.data.db.dao.migrations.Migration26;
|
||||
import io.github.wulkanowy.data.db.dao.migrations.Migration27;
|
||||
import io.github.wulkanowy.data.db.dao.migrations.Migration28;
|
||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
||||
import io.github.wulkanowy.di.annotations.DatabaseInfo;
|
||||
import io.github.wulkanowy.utils.LogUtils;
|
||||
|
||||
@Singleton
|
||||
@ -33,7 +32,7 @@ public class DbHelper extends DaoMaster.OpenHelper {
|
||||
private final Vulcan vulcan;
|
||||
|
||||
@Inject
|
||||
DbHelper(@ApplicationContext Context context, @DatabaseInfo String dbName,
|
||||
DbHelper(Context context, @Named("dbName") String dbName,
|
||||
SharedPrefContract sharedPref, Vulcan vulcan) {
|
||||
super(context, dbName);
|
||||
this.sharedPref = sharedPref;
|
||||
|
@ -15,7 +15,6 @@ import javax.inject.Singleton;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.api.NotLoggedInErrorException;
|
||||
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
||||
import io.github.wulkanowy.utils.AppConstant;
|
||||
import io.github.wulkanowy.utils.LogUtils;
|
||||
import io.github.wulkanowy.utils.security.CryptoException;
|
||||
@ -26,7 +25,7 @@ public class ResourcesRepository implements ResourcesContract {
|
||||
private Resources resources;
|
||||
|
||||
@Inject
|
||||
ResourcesRepository(@ApplicationContext Context context) {
|
||||
ResourcesRepository(Context context) {
|
||||
resources = context.getResources();
|
||||
}
|
||||
|
||||
|
@ -6,10 +6,9 @@ import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
||||
import io.github.wulkanowy.di.annotations.SharedPreferencesInfo;
|
||||
import io.github.wulkanowy.ui.main.settings.SettingsFragment;
|
||||
|
||||
@Singleton
|
||||
@ -24,7 +23,7 @@ public class SharedPrefRepository implements SharedPrefContract {
|
||||
private final SharedPreferences settingsSharedPref;
|
||||
|
||||
@Inject
|
||||
SharedPrefRepository(@ApplicationContext Context context, @SharedPreferencesInfo String sharedName) {
|
||||
SharedPrefRepository(Context context, @Named("sharedPrefName") String sharedName) {
|
||||
appSharedPref = context.getSharedPreferences(sharedName, Context.MODE_PRIVATE);
|
||||
settingsSharedPref = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import io.github.wulkanowy.data.db.dao.entities.StudentDao;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Symbol;
|
||||
import io.github.wulkanowy.data.db.dao.entities.SymbolDao;
|
||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
||||
import io.github.wulkanowy.utils.DataObjectConverter;
|
||||
import io.github.wulkanowy.utils.LogUtils;
|
||||
import io.github.wulkanowy.utils.security.CryptoException;
|
||||
@ -42,7 +41,7 @@ public class AccountSync {
|
||||
|
||||
@Inject
|
||||
AccountSync(DaoSession daoSession, SharedPrefContract sharedPref,
|
||||
Vulcan vulcan, @ApplicationContext Context context) {
|
||||
Vulcan vulcan, Context context) {
|
||||
this.daoSession = daoSession;
|
||||
this.sharedPref = sharedPref;
|
||||
this.vulcan = vulcan;
|
||||
|
20
app/src/main/java/io/github/wulkanowy/di/AppComponent.java
Normal file
20
app/src/main/java/io/github/wulkanowy/di/AppComponent.java
Normal file
@ -0,0 +1,20 @@
|
||||
package io.github.wulkanowy.di;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
import dagger.android.AndroidInjector;
|
||||
import dagger.android.support.AndroidSupportInjectionModule;
|
||||
import io.github.wulkanowy.WulkanowyApp;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
AndroidSupportInjectionModule.class,
|
||||
AppModule.class,
|
||||
BuilderModule.class
|
||||
})
|
||||
public interface AppComponent extends AndroidInjector<WulkanowyApp> {
|
||||
@Component.Builder
|
||||
abstract class Builder extends AndroidInjector.Builder<WulkanowyApp> {
|
||||
}
|
||||
}
|
78
app/src/main/java/io/github/wulkanowy/di/AppModule.java
Normal file
78
app/src/main/java/io/github/wulkanowy/di/AppModule.java
Normal file
@ -0,0 +1,78 @@
|
||||
package io.github.wulkanowy.di;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.github.wulkanowy.WulkanowyApp;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.data.Repository;
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.data.db.dao.DbContract;
|
||||
import io.github.wulkanowy.data.db.dao.DbHelper;
|
||||
import io.github.wulkanowy.data.db.dao.DbRepository;
|
||||
import io.github.wulkanowy.data.db.dao.entities.DaoMaster;
|
||||
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
|
||||
import io.github.wulkanowy.data.db.resources.ResourcesContract;
|
||||
import io.github.wulkanowy.data.db.resources.ResourcesRepository;
|
||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||
import io.github.wulkanowy.data.db.shared.SharedPrefRepository;
|
||||
import io.github.wulkanowy.data.sync.SyncContract;
|
||||
import io.github.wulkanowy.data.sync.SyncRepository;
|
||||
import io.github.wulkanowy.utils.AppConstant;
|
||||
|
||||
@Module
|
||||
public abstract class AppModule {
|
||||
|
||||
@Binds
|
||||
abstract Context provideContext(WulkanowyApp app);
|
||||
|
||||
@Singleton
|
||||
@Binds
|
||||
abstract RepositoryContract provideRepository(Repository repository);
|
||||
|
||||
@Singleton
|
||||
@Binds
|
||||
abstract DbContract provideDatabse(DbRepository dbRepository);
|
||||
|
||||
@Singleton
|
||||
@Binds
|
||||
abstract SharedPrefContract provideSharedPref(SharedPrefRepository sharedPrefRepository);
|
||||
|
||||
@Singleton
|
||||
@Binds
|
||||
abstract SyncContract provideSync(SyncRepository syncRepository);
|
||||
|
||||
@Singleton
|
||||
@Binds
|
||||
abstract ResourcesContract provideResources(ResourcesRepository resourcesRepository);
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
static DaoSession provideDaoSession(DbHelper dbHelper) {
|
||||
return new DaoMaster(dbHelper.getWritableDb()).newSession();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
static Vulcan provideVulcan() {
|
||||
return new Vulcan();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("dbName")
|
||||
static String provideDbName() {
|
||||
return AppConstant.DATABASE_NAME;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Named("sharedPrefName")
|
||||
static String provideSharedPrefName() {
|
||||
return AppConstant.SHARED_PREFERENCES_NAME;
|
||||
}
|
||||
|
||||
}
|
39
app/src/main/java/io/github/wulkanowy/di/BuilderModule.java
Normal file
39
app/src/main/java/io/github/wulkanowy/di/BuilderModule.java
Normal file
@ -0,0 +1,39 @@
|
||||
package io.github.wulkanowy.di;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.android.ContributesAndroidInjector;
|
||||
import io.github.wulkanowy.di.scopes.PerActivity;
|
||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||
import io.github.wulkanowy.services.widgets.TimetableWidgetServices;
|
||||
import io.github.wulkanowy.ui.login.LoginActivity;
|
||||
import io.github.wulkanowy.ui.login.LoginModule;
|
||||
import io.github.wulkanowy.ui.main.MainActivity;
|
||||
import io.github.wulkanowy.ui.main.MainModule;
|
||||
import io.github.wulkanowy.ui.splash.SplashActivity;
|
||||
import io.github.wulkanowy.ui.splash.SplashModule;
|
||||
import io.github.wulkanowy.ui.widgets.TimetableWidgetProvider;
|
||||
|
||||
@Module
|
||||
abstract class BuilderModule {
|
||||
|
||||
@PerActivity
|
||||
@ContributesAndroidInjector(modules = SplashModule.class)
|
||||
abstract SplashActivity bindSplashActivity();
|
||||
|
||||
@PerActivity
|
||||
@ContributesAndroidInjector(modules = LoginModule.class)
|
||||
abstract LoginActivity bindLoginActivity();
|
||||
|
||||
@PerActivity
|
||||
@ContributesAndroidInjector(modules = MainModule.class)
|
||||
abstract MainActivity bindMainActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract SyncJob bindSyncJob();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract TimetableWidgetServices bindTimetableWidgetServices();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract TimetableWidgetProvider bindTimetableWidgetProvider();
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package io.github.wulkanowy.di.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
@Qualifier
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ActivityContext {
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package io.github.wulkanowy.di.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
@Qualifier
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ApplicationContext {
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package io.github.wulkanowy.di.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
@Qualifier
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface SharedPreferencesInfo {
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package io.github.wulkanowy.di.component;
|
||||
|
||||
import dagger.Component;
|
||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||
import io.github.wulkanowy.di.modules.ActivityModule;
|
||||
import io.github.wulkanowy.ui.login.LoginActivity;
|
||||
import io.github.wulkanowy.ui.main.MainActivity;
|
||||
import io.github.wulkanowy.ui.splash.SplashActivity;
|
||||
|
||||
@PerActivity
|
||||
@Component(dependencies = ApplicationComponent.class, modules = ActivityModule.class)
|
||||
public interface ActivityComponent {
|
||||
|
||||
void inject(SplashActivity splashActivity);
|
||||
|
||||
void inject(LoginActivity loginActivity);
|
||||
|
||||
void inject(MainActivity mainActivity);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package io.github.wulkanowy.di.component;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
import io.github.wulkanowy.WulkanowyApp;
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
||||
import io.github.wulkanowy.di.modules.ApplicationModule;
|
||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||
import io.github.wulkanowy.ui.widgets.TimetableWidgetFactory;
|
||||
import io.github.wulkanowy.ui.widgets.TimetableWidgetProvider;
|
||||
|
||||
@Singleton
|
||||
@Component(modules = ApplicationModule.class)
|
||||
public interface ApplicationComponent {
|
||||
|
||||
@ApplicationContext
|
||||
Context getContext();
|
||||
|
||||
RepositoryContract getRepository();
|
||||
|
||||
void inject(WulkanowyApp wulkanowyApp);
|
||||
|
||||
void inject(SyncJob syncJob);
|
||||
|
||||
void inject(TimetableWidgetFactory timetableWidgetFactory);
|
||||
|
||||
void inject(TimetableWidgetProvider timetableWidgetProvider);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package io.github.wulkanowy.di.component;
|
||||
|
||||
import dagger.Component;
|
||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
||||
import io.github.wulkanowy.di.modules.FragmentModule;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendanceFragment;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendanceTabFragment;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsFragment;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsTabFragment;
|
||||
import io.github.wulkanowy.ui.main.grades.GradesFragment;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableTabFragment;
|
||||
|
||||
@PerFragment
|
||||
@Component(dependencies = ApplicationComponent.class, modules = FragmentModule.class)
|
||||
public interface FragmentComponent {
|
||||
|
||||
void inject(GradesFragment gradesFragment);
|
||||
|
||||
void inject(AttendanceFragment attendanceFragment);
|
||||
|
||||
void inject(AttendanceTabFragment attendanceTabFragment);
|
||||
|
||||
void inject(ExamsFragment examsFragment);
|
||||
|
||||
void inject(ExamsTabFragment examsTabFragment);
|
||||
|
||||
void inject(TimetableFragment timetableFragment);
|
||||
|
||||
void inject(TimetableTabFragment timetableTabFragment);
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
package io.github.wulkanowy.di.modules;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.github.wulkanowy.di.annotations.ActivityContext;
|
||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
import io.github.wulkanowy.ui.login.LoginContract;
|
||||
import io.github.wulkanowy.ui.login.LoginPresenter;
|
||||
import io.github.wulkanowy.ui.main.MainContract;
|
||||
import io.github.wulkanowy.ui.main.MainPresenter;
|
||||
import io.github.wulkanowy.ui.splash.SplashContract;
|
||||
import io.github.wulkanowy.ui.splash.SplashPresenter;
|
||||
|
||||
@Module
|
||||
public class ActivityModule {
|
||||
|
||||
private AppCompatActivity activity;
|
||||
|
||||
public ActivityModule(AppCompatActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@ActivityContext
|
||||
@Provides
|
||||
Context provideContext() {
|
||||
return activity;
|
||||
}
|
||||
|
||||
@Provides
|
||||
AppCompatActivity provideActivity() {
|
||||
return activity;
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
@Provides
|
||||
SplashContract.Presenter provideSplashPresenter
|
||||
(SplashPresenter splashPresenter) {
|
||||
return splashPresenter;
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
@Provides
|
||||
LoginContract.Presenter provideLoginPresenter
|
||||
(LoginPresenter loginPresenter) {
|
||||
return loginPresenter;
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
@Provides
|
||||
MainContract.Presenter provideMainPresenter
|
||||
(MainPresenter mainPresenter) {
|
||||
return mainPresenter;
|
||||
}
|
||||
|
||||
@Provides
|
||||
BasePagerAdapter provideMainPagerAdapter() {
|
||||
return new BasePagerAdapter(activity.getSupportFragmentManager());
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package io.github.wulkanowy.di.modules;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.firebase.jobdispatcher.FirebaseJobDispatcher;
|
||||
import com.firebase.jobdispatcher.GooglePlayDriver;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import io.github.wulkanowy.api.Vulcan;
|
||||
import io.github.wulkanowy.data.Repository;
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.data.db.dao.DbContract;
|
||||
import io.github.wulkanowy.data.db.dao.DbHelper;
|
||||
import io.github.wulkanowy.data.db.dao.DbRepository;
|
||||
import io.github.wulkanowy.data.db.dao.entities.DaoMaster;
|
||||
import io.github.wulkanowy.data.db.dao.entities.DaoSession;
|
||||
import io.github.wulkanowy.data.db.resources.ResourcesContract;
|
||||
import io.github.wulkanowy.data.db.resources.ResourcesRepository;
|
||||
import io.github.wulkanowy.data.db.shared.SharedPrefContract;
|
||||
import io.github.wulkanowy.data.db.shared.SharedPrefRepository;
|
||||
import io.github.wulkanowy.data.sync.SyncContract;
|
||||
import io.github.wulkanowy.data.sync.SyncRepository;
|
||||
import io.github.wulkanowy.di.annotations.ApplicationContext;
|
||||
import io.github.wulkanowy.di.annotations.DatabaseInfo;
|
||||
import io.github.wulkanowy.di.annotations.SharedPreferencesInfo;
|
||||
import io.github.wulkanowy.utils.AppConstant;
|
||||
|
||||
@Module
|
||||
public class ApplicationModule {
|
||||
|
||||
private final Application application;
|
||||
|
||||
public ApplicationModule(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
@Provides
|
||||
Application provideApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
@ApplicationContext
|
||||
@Provides
|
||||
Context provideAppContext() {
|
||||
return application;
|
||||
}
|
||||
|
||||
@DatabaseInfo
|
||||
@Provides
|
||||
String provideDatabaseName() {
|
||||
return AppConstant.DATABASE_NAME;
|
||||
}
|
||||
|
||||
@SharedPreferencesInfo
|
||||
@Provides
|
||||
String provideSharedPreferencesName() {
|
||||
return AppConstant.SHARED_PREFERENCES_NAME;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
DaoSession provideDaoSession(DbHelper dbHelper) {
|
||||
return new DaoMaster(dbHelper.getWritableDb()).newSession();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
Vulcan provideVulcan() {
|
||||
return new Vulcan();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
RepositoryContract provideRepository(Repository repository) {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
SharedPrefContract provideSharedPref(SharedPrefRepository sharedPrefRepository) {
|
||||
return sharedPrefRepository;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
ResourcesContract provideAppResources(ResourcesRepository resourcesRepository) {
|
||||
return resourcesRepository;
|
||||
}
|
||||
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
DbContract provideDatabase(DbRepository dbRepository) {
|
||||
return dbRepository;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
SyncContract provideSync(SyncRepository syncRepository) {
|
||||
return syncRepository;
|
||||
}
|
||||
|
||||
@Provides
|
||||
FirebaseJobDispatcher provideDispatcher() {
|
||||
return new FirebaseJobDispatcher(new GooglePlayDriver(application));
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
package io.github.wulkanowy.di.modules;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendanceContract;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendanceHeaderItem;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendancePresenter;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendanceTabContract;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendanceTabPresenter;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsContract;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsPresenter;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsSubItem;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsTabContract;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsTabPresenter;
|
||||
import io.github.wulkanowy.ui.main.grades.GradeHeaderItem;
|
||||
import io.github.wulkanowy.ui.main.grades.GradesContract;
|
||||
import io.github.wulkanowy.ui.main.grades.GradesPresenter;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableContract;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableHeaderItem;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetablePresenter;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableTabContract;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableTabPresenter;
|
||||
|
||||
@Module
|
||||
public class FragmentModule {
|
||||
|
||||
private final Fragment fragment;
|
||||
|
||||
public FragmentModule(Fragment fragment) {
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
@Provides
|
||||
GradesContract.Presenter provideGradesPresenter(GradesPresenter gradesPresenter) {
|
||||
return gradesPresenter;
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
@Provides
|
||||
AttendanceContract.Presenter provideAttendancePresenter(AttendancePresenter attendancePresenter) {
|
||||
return attendancePresenter;
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
@Provides
|
||||
ExamsContract.Presenter provideDashboardPresenter(ExamsPresenter examsPresenter) {
|
||||
return examsPresenter;
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
@Provides
|
||||
AttendanceTabContract.Presenter provideAttendanceTabPresenter(AttendanceTabPresenter timetableTabPresenter) {
|
||||
return timetableTabPresenter;
|
||||
}
|
||||
|
||||
@Provides
|
||||
BasePagerAdapter provideBasePagerAdapter() {
|
||||
return new BasePagerAdapter(fragment.getChildFragmentManager());
|
||||
}
|
||||
|
||||
@Provides
|
||||
FlexibleAdapter<AttendanceHeaderItem> provideAttendanceTabAdapter() {
|
||||
return new FlexibleAdapter<>(null);
|
||||
}
|
||||
|
||||
@Provides
|
||||
FlexibleAdapter<TimetableHeaderItem> provideTimetableTabAdapter() {
|
||||
return new FlexibleAdapter<>(null);
|
||||
}
|
||||
|
||||
@Provides
|
||||
FlexibleAdapter<GradeHeaderItem> provideGradesAdapter() {
|
||||
return new FlexibleAdapter<>(null);
|
||||
}
|
||||
|
||||
@Provides
|
||||
FlexibleAdapter<ExamsSubItem> provideExamAdapter() {
|
||||
return new FlexibleAdapter<>(null);
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
@Provides
|
||||
TimetableContract.Presenter provideTimetablePresenter(TimetablePresenter timetablePresenter) {
|
||||
return timetablePresenter;
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
@Provides
|
||||
TimetableTabContract.Presenter provideTimetableTabPresenter(TimetableTabPresenter timetableTabPresenter) {
|
||||
return timetableTabPresenter;
|
||||
}
|
||||
|
||||
@Provides
|
||||
ExamsTabContract.Presenter provideExamsTabPresenter(ExamsTabPresenter examsTabPresenter) {
|
||||
return examsTabPresenter;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.di.annotations;
|
||||
package io.github.wulkanowy.di.scopes;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
@ -1,11 +1,11 @@
|
||||
package io.github.wulkanowy.di.annotations;
|
||||
package io.github.wulkanowy.di.scopes;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
import javax.inject.Scope;
|
||||
|
||||
@Qualifier
|
||||
@Scope
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface DatabaseInfo {
|
||||
public @interface PerChildFragment {
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.di.annotations;
|
||||
package io.github.wulkanowy.di.scopes;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
@ -20,8 +20,8 @@ import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.AndroidInjection;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.WulkanowyApp;
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Grade;
|
||||
import io.github.wulkanowy.data.sync.NotRegisteredUserException;
|
||||
@ -60,7 +60,7 @@ public class SyncJob extends SimpleJobService {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
((WulkanowyApp) getApplication()).getApplicationComponent().inject(this);
|
||||
AndroidInjection.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,12 +3,20 @@ package io.github.wulkanowy.services.widgets;
|
||||
import android.content.Intent;
|
||||
import android.widget.RemoteViewsService;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.AndroidInjection;
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.ui.widgets.TimetableWidgetFactory;
|
||||
|
||||
public class TimetableWidgetServices extends RemoteViewsService {
|
||||
|
||||
@Inject
|
||||
RepositoryContract repository;
|
||||
|
||||
@Override
|
||||
public RemoteViewsFactory onGetViewFactory(Intent intent) {
|
||||
return new TimetableWidgetFactory(getApplicationContext());
|
||||
AndroidInjection.inject(this);
|
||||
return new TimetableWidgetFactory(getApplicationContext(), repository);
|
||||
}
|
||||
}
|
||||
|
@ -1,35 +1,51 @@
|
||||
package io.github.wulkanowy.ui.base;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.widget.Toast;
|
||||
import android.view.View;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import dagger.android.support.DaggerAppCompatActivity;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.WulkanowyApp;
|
||||
import io.github.wulkanowy.di.component.ActivityComponent;
|
||||
import io.github.wulkanowy.di.component.DaggerActivityComponent;
|
||||
import io.github.wulkanowy.di.modules.ActivityModule;
|
||||
import io.github.wulkanowy.utils.NetworkUtils;
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity implements BaseContract.View {
|
||||
|
||||
private ActivityComponent activityComponent;
|
||||
public abstract class BaseActivity extends DaggerAppCompatActivity implements BaseContract.View {
|
||||
|
||||
private Unbinder unbinder;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
||||
}
|
||||
|
||||
activityComponent = DaggerActivityComponent.builder()
|
||||
.activityModule(new ActivityModule(this))
|
||||
.applicationComponent(((WulkanowyApp) getApplication()).getApplicationComponent())
|
||||
.build();
|
||||
protected void injectViews() {
|
||||
unbinder = ButterKnife.bind(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showMessage(@NonNull String text) {
|
||||
if (getMessageView() != null) {
|
||||
Snackbar.make(getMessageView(), text, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showNoNetworkMessage() {
|
||||
showMessage(getString(R.string.noInternet_text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNetworkConnected() {
|
||||
return NetworkUtils.isOnline(getApplicationContext());
|
||||
}
|
||||
|
||||
protected View getMessageView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -39,32 +55,4 @@ public abstract class BaseActivity extends AppCompatActivity implements BaseCont
|
||||
unbinder.unbind();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int resId) {
|
||||
onError(getString(resId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoNetworkError() {
|
||||
onError(R.string.noInternet_text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNetworkConnected() {
|
||||
return NetworkUtils.isOnline(getApplicationContext());
|
||||
}
|
||||
|
||||
public ActivityComponent getActivityComponent() {
|
||||
return activityComponent;
|
||||
}
|
||||
|
||||
public void setButterKnife(Unbinder unbinder) {
|
||||
this.unbinder = unbinder;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,22 @@
|
||||
package io.github.wulkanowy.ui.base;
|
||||
|
||||
import android.support.annotation.StringRes;
|
||||
|
||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
public interface BaseContract {
|
||||
|
||||
interface View {
|
||||
|
||||
void onError(@StringRes int resId);
|
||||
void showMessage(@NonNull String text);
|
||||
|
||||
void onError(String message);
|
||||
|
||||
void onNoNetworkError();
|
||||
void showNoNetworkMessage();
|
||||
|
||||
boolean isNetworkConnected();
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
interface Presenter<V extends View> {
|
||||
|
||||
void onStart(V view);
|
||||
void attachView(@NonNull V view);
|
||||
|
||||
void onDestroy();
|
||||
void detachView();
|
||||
}
|
||||
}
|
||||
|
@ -1,56 +1,20 @@
|
||||
package io.github.wulkanowy.ui.base;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.view.View;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.WulkanowyApp;
|
||||
import io.github.wulkanowy.di.component.DaggerFragmentComponent;
|
||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||
import io.github.wulkanowy.di.modules.FragmentModule;
|
||||
import dagger.android.support.DaggerFragment;
|
||||
import io.github.wulkanowy.utils.NetworkUtils;
|
||||
|
||||
public abstract class BaseFragment extends Fragment implements BaseContract.View {
|
||||
|
||||
private BaseActivity activity;
|
||||
public abstract class BaseFragment extends DaggerFragment implements BaseContract.View {
|
||||
|
||||
private Unbinder unbinder;
|
||||
|
||||
private FragmentComponent fragmentComponent;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof BaseActivity) {
|
||||
activity = (BaseActivity) context;
|
||||
}
|
||||
|
||||
fragmentComponent = DaggerFragmentComponent.builder()
|
||||
.fragmentModule(new FragmentModule(this))
|
||||
.applicationComponent(((WulkanowyApp) activity.getApplication()).getApplicationComponent())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setHasOptionsMenu(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
setUpOnViewCreated(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
activity = null;
|
||||
super.onDetach();
|
||||
protected void injectViews(@NonNull View view) {
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -61,44 +25,32 @@ public abstract class BaseFragment extends Fragment implements BaseContract.View
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int resId) {
|
||||
onError(getString(resId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
if (activity != null) {
|
||||
activity.onError(message);
|
||||
public void setTitle(String title) {
|
||||
if (getActivity() != null) {
|
||||
getActivity().setTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNoNetworkError() {
|
||||
onError(R.string.noInternet_text);
|
||||
public void showMessage(@NonNull String text) {
|
||||
if (getActivity() != null) {
|
||||
((BaseActivity) getActivity()).showMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
public void showMessage(@StringRes int stringId) {
|
||||
showMessage(getString(stringId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showNoNetworkMessage() {
|
||||
if (getActivity() != null) {
|
||||
((BaseActivity) getActivity()).showNoNetworkMessage();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNetworkConnected() {
|
||||
return activity != null && activity.isNetworkConnected();
|
||||
}
|
||||
|
||||
public void setButterKnife(Unbinder unbinder) {
|
||||
this.unbinder = unbinder;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
if (activity != null) {
|
||||
activity.setTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
public FragmentComponent getFragmentComponent() {
|
||||
return fragmentComponent;
|
||||
}
|
||||
|
||||
|
||||
protected void setUpOnViewCreated(View fragmentView) {
|
||||
// do something on view created
|
||||
return NetworkUtils.isOnline(getContext());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package io.github.wulkanowy.ui.base;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
@ -16,12 +18,12 @@ public class BasePresenter<V extends BaseContract.View> implements BaseContract.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(V view) {
|
||||
public void attachView(@NonNull V view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
public void detachView() {
|
||||
view = null;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import android.animation.AnimatorListenerAdapter;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.TextInputLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.view.View;
|
||||
@ -18,7 +18,6 @@ import android.widget.TextView;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.OnEditorAction;
|
||||
import io.github.wulkanowy.R;
|
||||
@ -64,14 +63,10 @@ public class LoginActivity extends BaseActivity implements LoginContract.View {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
injectViews();
|
||||
|
||||
setButterKnife(ButterKnife.bind(this));
|
||||
getActivityComponent().inject(this);
|
||||
|
||||
presenter.onStart(this);
|
||||
|
||||
presenter.attachView(this);
|
||||
setUpOnCreate();
|
||||
|
||||
}
|
||||
|
||||
protected void setUpOnCreate() {
|
||||
@ -165,12 +160,6 @@ public class LoginActivity extends BaseActivity implements LoginContract.View {
|
||||
KeyboardUtils.hideSoftInput(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
Snackbar.make(findViewById(R.id.login_activity_container), message,
|
||||
Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStepOneLoginProgress() {
|
||||
onLoginProgressUpdate("1", getString(R.string.step_login));
|
||||
@ -222,13 +211,19 @@ public class LoginActivity extends BaseActivity implements LoginContract.View {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
presenter.onDestroy();
|
||||
protected View getMessageView() {
|
||||
return findViewById(R.id.login_activity_container);
|
||||
}
|
||||
|
||||
private void onLoginProgressUpdate(String step, String message) {
|
||||
loginProgressText.setText(String.format("%1$s/2 - %2$s...", step, message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
presenter.detachView();
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package io.github.wulkanowy.ui.login;
|
||||
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||
import io.github.wulkanowy.ui.base.BaseContract;
|
||||
|
||||
public interface LoginContract {
|
||||
@ -37,7 +35,6 @@ public interface LoginContract {
|
||||
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
|
||||
void attemptLogin(String email, String password, String symbol);
|
||||
@ -51,7 +48,5 @@ public interface LoginContract {
|
||||
void onEndAsync(boolean success, Exception exception);
|
||||
|
||||
void onCanceledAsync();
|
||||
|
||||
RepositoryContract getRepository();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package io.github.wulkanowy.ui.login;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import io.github.wulkanowy.di.scopes.PerActivity;
|
||||
|
||||
@Module
|
||||
public abstract class LoginModule {
|
||||
|
||||
@PerActivity
|
||||
@Binds
|
||||
abstract LoginContract.Presenter provideLoginPresenter(LoginPresenter loginPresenter);
|
||||
}
|
@ -47,7 +47,7 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
||||
loginAsync.execute();
|
||||
|
||||
} else {
|
||||
getView().onNoNetworkError();
|
||||
getView().showNoNetworkMessage();
|
||||
}
|
||||
|
||||
getView().hideSoftInput();
|
||||
@ -96,7 +96,7 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
||||
getView().showSoftInput();
|
||||
} else {
|
||||
FabricUtils.logRegister(false, symbol);
|
||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
}
|
||||
|
||||
getView().showActionBar(true);
|
||||
@ -160,11 +160,11 @@ public class LoginPresenter extends BasePresenter<LoginContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
public void detachView() {
|
||||
if (loginAsync != null) {
|
||||
loginAsync.cancel(true);
|
||||
loginAsync = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
super.detachView();
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
@ -13,9 +14,9 @@ import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem;
|
||||
import com.aurelhubert.ahbottomnavigation.AHBottomNavigationViewPager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||
import io.github.wulkanowy.ui.base.BaseActivity;
|
||||
@ -40,6 +41,7 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
||||
@BindView(R.id.main_activity_progress_bar)
|
||||
View progressBar;
|
||||
|
||||
@Named("Main")
|
||||
@Inject
|
||||
BasePagerAdapter pagerAdapter;
|
||||
|
||||
@ -55,11 +57,9 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
|
||||
injectViews();
|
||||
|
||||
getActivityComponent().inject(this);
|
||||
setButterKnife(ButterKnife.bind(this));
|
||||
|
||||
presenter.onStart(this, getIntent().getIntExtra(EXTRA_CARD_ID_KEY, -1));
|
||||
presenter.attachView(this, getIntent().getIntExtra(EXTRA_CARD_ID_KEY, -1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -146,9 +146,15 @@ public class MainActivity extends BaseActivity implements MainContract.View,
|
||||
SyncJob.start(getApplicationContext(), interval, useOnlyWifi);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected View getMessageView() {
|
||||
return findViewById(R.id.main_activity_view_pager);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
presenter.detachView();
|
||||
super.onDestroy();
|
||||
presenter.onDestroy();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main;
|
||||
|
||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import io.github.wulkanowy.ui.base.BaseContract;
|
||||
|
||||
public interface MainContract {
|
||||
@ -22,10 +23,9 @@ public interface MainContract {
|
||||
void startSyncService(int interval, boolean useOnlyWifi);
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
|
||||
void onStart(View view, int tabPositionIntent);
|
||||
void attachView(@NonNull View view, int initTabId);
|
||||
|
||||
void onTabSelected(int position, boolean wasSelected);
|
||||
|
||||
|
@ -0,0 +1,50 @@
|
||||
package io.github.wulkanowy.ui.main;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.android.ContributesAndroidInjector;
|
||||
import io.github.wulkanowy.di.scopes.PerActivity;
|
||||
import io.github.wulkanowy.di.scopes.PerFragment;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendanceFragment;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendanceModule;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsFragment;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsModule;
|
||||
import io.github.wulkanowy.ui.main.grades.GradesFragment;
|
||||
import io.github.wulkanowy.ui.main.grades.GradesModule;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableFragment;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableModule;
|
||||
|
||||
@Module
|
||||
public abstract class MainModule {
|
||||
|
||||
@PerActivity
|
||||
@Binds
|
||||
abstract MainContract.Presenter provideMainPresenter(MainPresenter mainPresenter);
|
||||
|
||||
@Named("Main")
|
||||
@PerActivity
|
||||
@Provides
|
||||
static BasePagerAdapter provideAdapter(MainActivity activity) {
|
||||
return new BasePagerAdapter(activity.getSupportFragmentManager());
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector(modules = GradesModule.class)
|
||||
abstract GradesFragment bindsGradesFragment();
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector(modules = TimetableModule.class)
|
||||
abstract TimetableFragment bindTimetableFragment();
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector(modules = ExamsModule.class)
|
||||
abstract ExamsFragment bindExamsFragment();
|
||||
|
||||
@PerFragment
|
||||
@ContributesAndroidInjector(modules = AttendanceModule.class)
|
||||
abstract AttendanceFragment bindAttendanceFramgnet();
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package io.github.wulkanowy.ui.main;
|
||||
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
@ -17,15 +19,15 @@ public class MainPresenter extends BasePresenter<MainContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(MainContract.View view, int tabPositionIntent) {
|
||||
super.onStart(view);
|
||||
public void attachView(@NonNull MainContract.View view, int initTabId) {
|
||||
super.attachView(view);
|
||||
getView().showProgressBar(true);
|
||||
getView().hideActionBar();
|
||||
|
||||
int tabPosition;
|
||||
|
||||
if (tabPositionIntent != -1) {
|
||||
tabPosition = tabPositionIntent;
|
||||
if (initTabId != -1) {
|
||||
tabPosition = initTabId;
|
||||
} else {
|
||||
tabPosition = getRepository().getSharedRepo().getStartupTab();
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.attendance;
|
||||
|
||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import io.github.wulkanowy.ui.base.BaseContract;
|
||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||
|
||||
@ -21,12 +22,11 @@ public interface AttendanceContract {
|
||||
void setThemeForTab(int position);
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
|
||||
void onFragmentActivated(boolean isVisible);
|
||||
|
||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
||||
void attachView(@NonNull View view, OnFragmentIsReadyListener listener);
|
||||
|
||||
void setRestoredPosition(int position);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package io.github.wulkanowy.ui.main.attendance;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.LayoutInflater;
|
||||
@ -11,14 +10,14 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||
import io.github.wulkanowy.ui.main.attendance.tab.AttendanceTabFragment;
|
||||
|
||||
public class AttendanceFragment extends BaseFragment implements AttendanceContract.View {
|
||||
|
||||
@ -31,6 +30,7 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
||||
TabLayout tabLayout;
|
||||
|
||||
@Inject
|
||||
@Named("Attendance")
|
||||
BasePagerAdapter pagerAdapter;
|
||||
|
||||
@Inject
|
||||
@ -41,18 +41,13 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_attendance, container, false);
|
||||
injectViews(view);
|
||||
|
||||
FragmentComponent component = getFragmentComponent();
|
||||
if (component != null) {
|
||||
component.inject(this);
|
||||
setButterKnife(ButterKnife.bind(this, view));
|
||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
||||
presenter.attachView(this, (OnFragmentIsReadyListener) getActivity());
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||
}
|
||||
if (savedInstanceState != null) {
|
||||
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -93,14 +88,6 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
||||
setTitle(getString(R.string.attendance_text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
if (getActivity() != null) {
|
||||
Snackbar.make(getActivity().findViewById(R.id.main_activity_view_pager),
|
||||
message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(CURRENT_ITEM_KEY, viewPager.getCurrentItem());
|
||||
@ -109,7 +96,7 @@ public class AttendanceFragment extends BaseFragment implements AttendanceContra
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
presenter.onDestroy();
|
||||
presenter.detachView();
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package io.github.wulkanowy.ui.main.attendance;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.android.ContributesAndroidInjector;
|
||||
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||
import io.github.wulkanowy.di.scopes.PerFragment;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
import io.github.wulkanowy.ui.main.attendance.tab.AttendanceTabFragment;
|
||||
import io.github.wulkanowy.ui.main.attendance.tab.AttendanceTabModule;
|
||||
|
||||
@Module
|
||||
public abstract class AttendanceModule {
|
||||
|
||||
@PerFragment
|
||||
@Binds
|
||||
abstract AttendanceContract.Presenter provideAttendancePresenter(AttendancePresenter attendancePresenter);
|
||||
|
||||
@PerFragment
|
||||
@Named("Attendance")
|
||||
@Provides
|
||||
static BasePagerAdapter providePagerAdapter(AttendanceFragment fragment) {
|
||||
return new BasePagerAdapter(fragment.getChildFragmentManager());
|
||||
}
|
||||
|
||||
@PerChildFragment
|
||||
@ContributesAndroidInjector(modules = AttendanceTabModule.class)
|
||||
abstract AttendanceTabFragment bindAttendanceTabFragment();
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.attendance;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -31,8 +33,8 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(AttendanceContract.View view, OnFragmentIsReadyListener listener) {
|
||||
super.onStart(view);
|
||||
public void attachView(@NonNull AttendanceContract.View view, OnFragmentIsReadyListener listener) {
|
||||
super.attachView(view);
|
||||
this.listener = listener;
|
||||
|
||||
if (getView().isMenuVisible()) {
|
||||
@ -64,7 +66,7 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDoInBackgroundLoading() throws Exception {
|
||||
public void onDoInBackgroundLoading() {
|
||||
for (String date : dates) {
|
||||
getView().setTabDataToAdapter(date);
|
||||
}
|
||||
@ -92,14 +94,13 @@ public class AttendancePresenter extends BasePresenter<AttendanceContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
public void detachView() {
|
||||
isFirstSight = false;
|
||||
|
||||
if (loadingTask != null) {
|
||||
loadingTask.cancel(true);
|
||||
loadingTask = null;
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
super.detachView();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.main.attendance;
|
||||
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.main.attendance;
|
||||
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
@ -20,6 +20,7 @@ import eu.davidea.flexibleadapter.items.IFlexible;
|
||||
import eu.davidea.viewholders.FlexibleViewHolder;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.data.db.dao.entities.AttendanceLesson;
|
||||
import io.github.wulkanowy.ui.main.attendance.AttendanceDialogFragment;
|
||||
|
||||
class AttendanceSubItem
|
||||
extends AbstractSectionableItem<AttendanceSubItem.SubItemViewHolder, AttendanceHeaderItem> {
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.main.attendance;
|
||||
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,9 +1,8 @@
|
||||
package io.github.wulkanowy.ui.main.attendance;
|
||||
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
@ -15,11 +14,9 @@ import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||
|
||||
public class AttendanceTabFragment extends BaseFragment implements AttendanceTabContract.View,
|
||||
@ -61,34 +58,28 @@ public class AttendanceTabFragment extends BaseFragment implements AttendanceTab
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_attendance_tab, container, false);
|
||||
injectViews(view);
|
||||
|
||||
FragmentComponent component = getFragmentComponent();
|
||||
if (component != null) {
|
||||
component.inject(this);
|
||||
setButterKnife(ButterKnife.bind(this, view));
|
||||
|
||||
if (getArguments() != null) {
|
||||
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||
}
|
||||
|
||||
presenter.onStart(this);
|
||||
presenter.onFragmentActivated(isFragmentVisible);
|
||||
if (getArguments() != null) {
|
||||
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||
}
|
||||
|
||||
presenter.attachView(this);
|
||||
presenter.onFragmentActivated(isFragmentVisible);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpOnViewCreated(View fragmentView) {
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
adapter.setAutoCollapseOnExpand(true);
|
||||
adapter.setAutoScrollOnExpand(true);
|
||||
adapter.expandItemsAtStartUp();
|
||||
|
||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(fragmentView.getContext()));
|
||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(view.getContext()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
refreshLayout.setColorSchemeResources(android.R.color.black);
|
||||
refreshLayout.setOnRefreshListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -112,7 +103,7 @@ public class AttendanceTabFragment extends BaseFragment implements AttendanceTab
|
||||
|
||||
@Override
|
||||
public void onRefreshSuccess() {
|
||||
onError(R.string.sync_completed);
|
||||
showMessage(R.string.sync_completed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -130,17 +121,9 @@ public class AttendanceTabFragment extends BaseFragment implements AttendanceTab
|
||||
noItemView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
if (getActivity() != null) {
|
||||
Snackbar.make(getActivity().findViewById(R.id.main_activity_view_pager),
|
||||
message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
presenter.onDestroy();
|
||||
presenter.detachView();
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||
|
||||
@Module
|
||||
public abstract class AttendanceTabModule {
|
||||
|
||||
@PerChildFragment
|
||||
@Binds
|
||||
abstract AttendanceTabContract.Presenter provideAttendanceTabPresenter(AttendanceTabPresenter attendanceTabPresenter);
|
||||
|
||||
@PerChildFragment
|
||||
@Provides
|
||||
static FlexibleAdapter<AttendanceHeaderItem> provideAdapter() {
|
||||
return new FlexibleAdapter<>(null);
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
package io.github.wulkanowy.ui.main.attendance;
|
||||
package io.github.wulkanowy.ui.main.attendance.tab;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -34,8 +36,9 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(AttendanceTabContract.View view) {
|
||||
super.onStart(view);
|
||||
public void attachView(@NonNull AttendanceTabContract.View view) {
|
||||
super.attachView(view);
|
||||
|
||||
getView().showProgressBar(true);
|
||||
getView().showNoItem(false);
|
||||
}
|
||||
@ -60,7 +63,7 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
|
||||
refreshTask.setOnRefreshListener(this);
|
||||
refreshTask.execute();
|
||||
} else {
|
||||
getView().onNoNetworkError();
|
||||
getView().showNoNetworkMessage();
|
||||
getView().hideRefreshingBar();
|
||||
}
|
||||
}
|
||||
@ -86,7 +89,7 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
|
||||
|
||||
getView().onRefreshSuccess();
|
||||
} else {
|
||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
}
|
||||
getView().hideRefreshingBar();
|
||||
|
||||
@ -183,9 +186,9 @@ public class AttendanceTabPresenter extends BasePresenter<AttendanceTabContract.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
public void detachView() {
|
||||
cancelAsyncTasks();
|
||||
isFirstSight = false;
|
||||
super.onDestroy();
|
||||
super.detachView();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.exams;
|
||||
|
||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import io.github.wulkanowy.ui.base.BaseContract;
|
||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||
|
||||
@ -21,10 +22,9 @@ public interface ExamsContract {
|
||||
void setThemeForTab(int position);
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
|
||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
||||
void attachView(@NonNull View view, OnFragmentIsReadyListener listener);
|
||||
|
||||
void onFragmentActivated(boolean isVisible);
|
||||
|
||||
|
@ -10,14 +10,15 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||
import io.github.wulkanowy.ui.main.exams.tab.ExamsTabFragment;
|
||||
|
||||
public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
||||
|
||||
@ -30,6 +31,7 @@ public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
||||
TabLayout tabLayout;
|
||||
|
||||
@Inject
|
||||
@Named("Exams")
|
||||
BasePagerAdapter pagerAdapter;
|
||||
|
||||
@Inject
|
||||
@ -39,16 +41,12 @@ public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_exams, container, false);
|
||||
injectViews(view);
|
||||
|
||||
FragmentComponent component = getFragmentComponent();
|
||||
if (component != null) {
|
||||
component.inject(this);
|
||||
setButterKnife(ButterKnife.bind(this, view));
|
||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
||||
presenter.attachView(this, (OnFragmentIsReadyListener) getActivity());
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||
}
|
||||
if (savedInstanceState != null) {
|
||||
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||
}
|
||||
return view;
|
||||
}
|
||||
@ -61,14 +59,6 @@ public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
if (getActivity() != null) {
|
||||
Snackbar.make(getActivity().findViewById(R.id.main_activity_view_pager),
|
||||
message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivityTitle() {
|
||||
setTitle(getString(R.string.exams_text));
|
||||
@ -107,6 +97,6 @@ public class ExamsFragment extends BaseFragment implements ExamsContract.View {
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
presenter.onDestroy();
|
||||
presenter.detachView();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package io.github.wulkanowy.ui.main.exams;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.android.ContributesAndroidInjector;
|
||||
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||
import io.github.wulkanowy.di.scopes.PerFragment;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
import io.github.wulkanowy.ui.main.exams.tab.ExamsTabFragment;
|
||||
import io.github.wulkanowy.ui.main.exams.tab.ExamsTabModule;
|
||||
|
||||
@Module
|
||||
public abstract class ExamsModule {
|
||||
|
||||
@PerFragment
|
||||
@Binds
|
||||
abstract ExamsContract.Presenter provideExamsPresneter(ExamsPresenter examsPresenter);
|
||||
|
||||
@Named("Exams")
|
||||
@PerFragment
|
||||
@Provides
|
||||
static BasePagerAdapter providePagerAdapter(ExamsFragment fragment) {
|
||||
return new BasePagerAdapter(fragment.getChildFragmentManager());
|
||||
}
|
||||
|
||||
@PerChildFragment
|
||||
@ContributesAndroidInjector(modules = ExamsTabModule.class)
|
||||
abstract ExamsTabFragment bindExamsTabFragment();
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.exams;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -31,8 +33,8 @@ public class ExamsPresenter extends BasePresenter<ExamsContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(ExamsContract.View view, OnFragmentIsReadyListener listener) {
|
||||
super.onStart(view);
|
||||
public void attachView(@NonNull ExamsContract.View view, OnFragmentIsReadyListener listener) {
|
||||
super.attachView(view);
|
||||
this.listener = listener;
|
||||
|
||||
if (getView().isMenuVisible()) {
|
||||
@ -69,7 +71,7 @@ public class ExamsPresenter extends BasePresenter<ExamsContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDoInBackgroundLoading() throws Exception {
|
||||
public void onDoInBackgroundLoading() {
|
||||
for (String date : dates) {
|
||||
getView().setTabDataToAdapter(date);
|
||||
}
|
||||
@ -91,13 +93,13 @@ public class ExamsPresenter extends BasePresenter<ExamsContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
public void detachView() {
|
||||
isFirstSight = false;
|
||||
|
||||
if (loadingTask != null) {
|
||||
loadingTask.cancel(true);
|
||||
loadingTask = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
super.detachView();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.main.exams;
|
||||
package io.github.wulkanowy.ui.main.exams.tab;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
@ -22,7 +22,7 @@ public class ExamsHeaderItem extends AbstractHeaderItem<ExamsHeaderItem.HeaderVi
|
||||
|
||||
private Day day;
|
||||
|
||||
public ExamsHeaderItem(Day day) {
|
||||
ExamsHeaderItem(Day day) {
|
||||
this.day = day;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.main.exams;
|
||||
package io.github.wulkanowy.ui.main.exams.tab;
|
||||
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
@ -18,6 +18,7 @@ import eu.davidea.flexibleadapter.items.IFlexible;
|
||||
import eu.davidea.viewholders.FlexibleViewHolder;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Exam;
|
||||
import io.github.wulkanowy.ui.main.exams.ExamsDialogFragment;
|
||||
|
||||
public class ExamsSubItem
|
||||
extends AbstractSectionableItem<ExamsSubItem.SubItemViewHolder, ExamsHeaderItem> {
|
@ -1,8 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.exams;
|
||||
package io.github.wulkanowy.ui.main.exams.tab;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
||||
import io.github.wulkanowy.ui.base.BaseContract;
|
||||
|
||||
public interface ExamsTabContract {
|
||||
@ -20,7 +19,6 @@ public interface ExamsTabContract {
|
||||
void updateAdapterList(List<ExamsSubItem> headerItems);
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
|
||||
void onFragmentActivated(boolean isSelected);
|
@ -1,8 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.exams;
|
||||
package io.github.wulkanowy.ui.main.exams.tab;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
@ -14,11 +13,9 @@ import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||
|
||||
public class ExamsTabFragment extends BaseFragment implements ExamsTabContract.View,
|
||||
@ -60,26 +57,21 @@ public class ExamsTabFragment extends BaseFragment implements ExamsTabContract.V
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_exams_tab, container, false);
|
||||
injectViews(view);
|
||||
|
||||
FragmentComponent component = getFragmentComponent();
|
||||
if (component != null) {
|
||||
component.inject(this);
|
||||
setButterKnife(ButterKnife.bind(this, view));
|
||||
|
||||
if (getArguments() != null) {
|
||||
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||
}
|
||||
presenter.onStart(this);
|
||||
presenter.onFragmentActivated(isFragmentVisible);
|
||||
if (getArguments() != null) {
|
||||
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||
}
|
||||
presenter.attachView(this);
|
||||
presenter.onFragmentActivated(isFragmentVisible);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpOnViewCreated(View fragmentView) {
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
adapter.setDisplayHeadersAtStartUp(true);
|
||||
|
||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(fragmentView.getContext()));
|
||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(view.getContext()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
refreshLayout.setColorSchemeResources(android.R.color.black);
|
||||
@ -107,7 +99,7 @@ public class ExamsTabFragment extends BaseFragment implements ExamsTabContract.V
|
||||
|
||||
@Override
|
||||
public void onRefreshSuccess() {
|
||||
onError(R.string.sync_completed);
|
||||
showMessage(R.string.sync_completed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -125,17 +117,10 @@ public class ExamsTabFragment extends BaseFragment implements ExamsTabContract.V
|
||||
progressBar.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
if (getActivity() != null) {
|
||||
Snackbar.make(getActivity().findViewById(R.id.main_activity_view_pager),
|
||||
message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
presenter.onDestroy();
|
||||
presenter.detachView();
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package io.github.wulkanowy.ui.main.exams.tab;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||
|
||||
@Module
|
||||
public abstract class ExamsTabModule {
|
||||
|
||||
@PerChildFragment
|
||||
@Binds
|
||||
abstract ExamsTabContract.Presenter provideExamsTabPresenter(ExamsTabPresenter examsTabPresenter);
|
||||
|
||||
@PerChildFragment
|
||||
@Provides
|
||||
static FlexibleAdapter<ExamsSubItem> provideAdapter() {
|
||||
return new FlexibleAdapter<>(null);
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
package io.github.wulkanowy.ui.main.exams;
|
||||
package io.github.wulkanowy.ui.main.exams.tab;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -29,13 +31,13 @@ public class ExamsTabPresenter extends BasePresenter<ExamsTabContract.View>
|
||||
private boolean isFirstSight = false;
|
||||
|
||||
@Inject
|
||||
public ExamsTabPresenter(RepositoryContract repository) {
|
||||
ExamsTabPresenter(RepositoryContract repository) {
|
||||
super(repository);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(ExamsTabContract.View view) {
|
||||
super.onStart(view);
|
||||
public void attachView(@NonNull ExamsTabContract.View view) {
|
||||
super.attachView(view);
|
||||
getView().showProgressBar(true);
|
||||
getView().showNoItem(false);
|
||||
}
|
||||
@ -65,7 +67,7 @@ public class ExamsTabPresenter extends BasePresenter<ExamsTabContract.View>
|
||||
refreshTask.setOnRefreshListener(this);
|
||||
refreshTask.execute();
|
||||
} else {
|
||||
getView().onNoNetworkError();
|
||||
getView().showNoNetworkMessage();
|
||||
getView().hideRefreshingBar();
|
||||
}
|
||||
}
|
||||
@ -91,7 +93,7 @@ public class ExamsTabPresenter extends BasePresenter<ExamsTabContract.View>
|
||||
|
||||
getView().onRefreshSuccess();
|
||||
} else {
|
||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
}
|
||||
getView().hideRefreshingBar();
|
||||
|
||||
@ -157,9 +159,9 @@ public class ExamsTabPresenter extends BasePresenter<ExamsTabContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
public void detachView() {
|
||||
isFirstSight = false;
|
||||
cancelAsyncTasks();
|
||||
super.onDestroy();
|
||||
super.detachView();
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package io.github.wulkanowy.ui.main.grades;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||
import io.github.wulkanowy.ui.base.BaseContract;
|
||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||
|
||||
@ -30,14 +30,13 @@ public interface GradesContract {
|
||||
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
|
||||
void onFragmentVisible(boolean isVisible);
|
||||
|
||||
void onRefresh();
|
||||
|
||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
||||
void attachView(@NonNull View view, OnFragmentIsReadyListener listener);
|
||||
|
||||
void onSemesterChange(int which);
|
||||
|
||||
|
@ -4,7 +4,6 @@ import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
@ -20,11 +19,9 @@ import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||
|
||||
@ -55,14 +52,9 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_grades, container, false);
|
||||
injectViews(view);
|
||||
|
||||
FragmentComponent component = getFragmentComponent();
|
||||
if (component != null) {
|
||||
component.inject(this);
|
||||
setButterKnife(ButterKnife.bind(this, view));
|
||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
||||
}
|
||||
|
||||
presenter.attachView(this, (OnFragmentIsReadyListener) getActivity());
|
||||
return view;
|
||||
}
|
||||
|
||||
@ -102,14 +94,14 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpOnViewCreated(View fragmentView) {
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
noItemView.setVisibility(View.GONE);
|
||||
|
||||
adapter.setAutoCollapseOnExpand(true);
|
||||
adapter.setAutoScrollOnExpand(true);
|
||||
adapter.expandItemsAtStartUp();
|
||||
|
||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(fragmentView.getContext()));
|
||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(view.getContext()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
refreshLayout.setColorSchemeResources(android.R.color.black);
|
||||
@ -155,25 +147,17 @@ public class GradesFragment extends BaseFragment implements GradesContract.View
|
||||
|
||||
@Override
|
||||
public void onRefreshSuccessNoGrade() {
|
||||
onError(R.string.snackbar_no_grades);
|
||||
showMessage(R.string.snackbar_no_grades);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefreshSuccess(int number) {
|
||||
onError(getString(R.string.snackbar_new_grade, number));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
if (getActivity() != null) {
|
||||
Snackbar.make(getActivity().findViewById(R.id.main_activity_view_pager),
|
||||
message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
showMessage(getString(R.string.snackbar_new_grade, number));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
presenter.onDestroy();
|
||||
presenter.detachView();
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package io.github.wulkanowy.ui.main.grades;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
|
||||
@Module
|
||||
public abstract class GradesModule {
|
||||
|
||||
@Binds
|
||||
abstract GradesContract.Presenter provideGradesPresenter(GradesPresenter gradesPresenter);
|
||||
|
||||
@Provides
|
||||
static FlexibleAdapter<GradeHeaderItem> provideGradesAdapter() {
|
||||
return new FlexibleAdapter<>(null);
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.grades;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.crashlytics.android.answers.Answers;
|
||||
import com.crashlytics.android.answers.CustomEvent;
|
||||
|
||||
@ -41,8 +43,8 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(GradesContract.View view, OnFragmentIsReadyListener listener) {
|
||||
super.onStart(view);
|
||||
public void attachView(@NonNull GradesContract.View view, OnFragmentIsReadyListener listener) {
|
||||
super.attachView(view);
|
||||
this.listener = listener;
|
||||
|
||||
if (getView().isMenuVisible()) {
|
||||
@ -94,7 +96,7 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
refreshTask.setOnRefreshListener(this);
|
||||
refreshTask.execute();
|
||||
} else {
|
||||
getView().onNoNetworkError();
|
||||
getView().showNoNetworkMessage();
|
||||
getView().hideRefreshingBar();
|
||||
}
|
||||
}
|
||||
@ -125,7 +127,7 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
getView().onRefreshSuccess(numberOfNewGrades);
|
||||
}
|
||||
} else {
|
||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
}
|
||||
getView().hideRefreshingBar();
|
||||
|
||||
@ -183,9 +185,9 @@ public class GradesPresenter extends BasePresenter<GradesContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
public void detachView() {
|
||||
isFirstSight = false;
|
||||
cancelAsyncTasks();
|
||||
super.onDestroy();
|
||||
super.detachView();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.timetable;
|
||||
|
||||
import io.github.wulkanowy.di.annotations.PerFragment;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import io.github.wulkanowy.ui.base.BaseContract;
|
||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||
|
||||
@ -21,12 +22,11 @@ public interface TimetableContract {
|
||||
void setThemeForTab(int position);
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
|
||||
void onFragmentActivated(boolean isVisible);
|
||||
|
||||
void onStart(View view, OnFragmentIsReadyListener listener);
|
||||
void attachView(@NonNull View view, OnFragmentIsReadyListener listener);
|
||||
|
||||
void setRestoredPosition(int position);
|
||||
}
|
||||
|
@ -11,14 +11,14 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
import io.github.wulkanowy.ui.main.OnFragmentIsReadyListener;
|
||||
import io.github.wulkanowy.ui.main.timetable.tab.TimetableTabFragment;
|
||||
|
||||
public class TimetableFragment extends BaseFragment implements TimetableContract.View {
|
||||
|
||||
@ -30,6 +30,7 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
||||
@BindView(R.id.timetable_fragment_tab_layout)
|
||||
TabLayout tabLayout;
|
||||
|
||||
@Named("Timetable")
|
||||
@Inject
|
||||
BasePagerAdapter pagerAdapter;
|
||||
|
||||
@ -40,16 +41,12 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_timetable, container, false);
|
||||
injectViews(view);
|
||||
|
||||
FragmentComponent component = getFragmentComponent();
|
||||
if (component != null) {
|
||||
component.inject(this);
|
||||
setButterKnife(ButterKnife.bind(this, view));
|
||||
presenter.onStart(this, (OnFragmentIsReadyListener) getActivity());
|
||||
presenter.attachView(this, (OnFragmentIsReadyListener) getActivity());
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||
}
|
||||
if (savedInstanceState != null) {
|
||||
presenter.setRestoredPosition(savedInstanceState.getInt(CURRENT_ITEM_KEY));
|
||||
}
|
||||
return view;
|
||||
}
|
||||
@ -91,14 +88,6 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
||||
setTitle(getString(R.string.timetable_text));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
if (getActivity() != null) {
|
||||
Snackbar.make(getActivity().findViewById(R.id.main_activity_view_pager),
|
||||
message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putInt(CURRENT_ITEM_KEY, viewPager.getCurrentItem());
|
||||
@ -107,7 +96,7 @@ public class TimetableFragment extends BaseFragment implements TimetableContract
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
presenter.onDestroy();
|
||||
presenter.detachView();
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package io.github.wulkanowy.ui.main.timetable;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.android.ContributesAndroidInjector;
|
||||
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||
import io.github.wulkanowy.di.scopes.PerFragment;
|
||||
import io.github.wulkanowy.ui.base.BasePagerAdapter;
|
||||
import io.github.wulkanowy.ui.main.timetable.tab.TimetableTabFragment;
|
||||
import io.github.wulkanowy.ui.main.timetable.tab.TimetableTabModule;
|
||||
|
||||
@Module
|
||||
public abstract class TimetableModule {
|
||||
|
||||
@Named("Timetable")
|
||||
@PerFragment
|
||||
@Provides
|
||||
static BasePagerAdapter providePagerAdapter(TimetableFragment fragment) {
|
||||
return new BasePagerAdapter(fragment.getChildFragmentManager());
|
||||
}
|
||||
|
||||
@PerFragment
|
||||
@Binds
|
||||
abstract TimetableContract.Presenter provideTimetablePresenter(TimetablePresenter timetablePresenter);
|
||||
|
||||
@PerChildFragment
|
||||
@ContributesAndroidInjector(modules = TimetableTabModule.class)
|
||||
abstract TimetableTabFragment bindTimetableTabFragment();
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.timetable;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -31,8 +33,8 @@ public class TimetablePresenter extends BasePresenter<TimetableContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(TimetableContract.View view, OnFragmentIsReadyListener listener) {
|
||||
super.onStart(view);
|
||||
public void attachView(@NonNull TimetableContract.View view, OnFragmentIsReadyListener listener) {
|
||||
super.attachView(view);
|
||||
this.listener = listener;
|
||||
|
||||
if (getView().isMenuVisible()) {
|
||||
@ -64,7 +66,7 @@ public class TimetablePresenter extends BasePresenter<TimetableContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDoInBackgroundLoading() throws Exception {
|
||||
public void onDoInBackgroundLoading() {
|
||||
for (String date : dates) {
|
||||
getView().setTabDataToAdapter(date);
|
||||
}
|
||||
@ -91,13 +93,13 @@ public class TimetablePresenter extends BasePresenter<TimetableContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
public void detachView() {
|
||||
isFirstSight = false;
|
||||
|
||||
if (loadingTask != null) {
|
||||
loadingTask.cancel(true);
|
||||
loadingTask = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
super.detachView();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.main.timetable;
|
||||
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.main.timetable;
|
||||
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Paint;
|
||||
@ -21,6 +21,7 @@ import eu.davidea.flexibleadapter.items.IFlexible;
|
||||
import eu.davidea.viewholders.FlexibleViewHolder;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
||||
import io.github.wulkanowy.ui.main.timetable.TimetableDialogFragment;
|
||||
|
||||
|
||||
public class TimetableSubItem
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.main.timetable;
|
||||
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package io.github.wulkanowy.ui.main.timetable;
|
||||
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
@ -16,11 +16,9 @@ import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.di.component.FragmentComponent;
|
||||
import io.github.wulkanowy.ui.base.BaseFragment;
|
||||
|
||||
public class TimetableTabFragment extends BaseFragment implements TimetableTabContract.View,
|
||||
@ -65,33 +63,27 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_timetable_tab, container, false);
|
||||
injectViews(view);
|
||||
|
||||
FragmentComponent component = getFragmentComponent();
|
||||
if (component != null) {
|
||||
component.inject(this);
|
||||
setButterKnife(ButterKnife.bind(this, view));
|
||||
|
||||
if (getArguments() != null) {
|
||||
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||
}
|
||||
presenter.onStart(this);
|
||||
presenter.onFragmentActivated(isFragmentVisible);
|
||||
if (getArguments() != null) {
|
||||
presenter.setArgumentDate(getArguments().getString(ARGUMENT_KEY));
|
||||
}
|
||||
presenter.attachView(this);
|
||||
presenter.onFragmentActivated(isFragmentVisible);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUpOnViewCreated(View fragmentView) {
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
adapter.setAutoCollapseOnExpand(true);
|
||||
adapter.setAutoScrollOnExpand(true);
|
||||
adapter.expandItemsAtStartUp();
|
||||
|
||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(fragmentView.getContext()));
|
||||
recyclerView.setLayoutManager(new SmoothScrollLinearLayoutManager(view.getContext()));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
refreshLayout.setColorSchemeResources(android.R.color.black);
|
||||
refreshLayout.setOnRefreshListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -120,7 +112,7 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
|
||||
|
||||
@Override
|
||||
public void onRefreshSuccess() {
|
||||
onError(R.string.sync_completed);
|
||||
showMessage(R.string.sync_completed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -138,17 +130,9 @@ public class TimetableTabFragment extends BaseFragment implements TimetableTabCo
|
||||
noItemView.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String message) {
|
||||
if (getActivity() != null) {
|
||||
Snackbar.make(getActivity().findViewById(R.id.main_activity_view_pager),
|
||||
message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
presenter.onDestroy();
|
||||
presenter.detachView();
|
||||
super.onDestroyView();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
||||
import io.github.wulkanowy.di.scopes.PerChildFragment;
|
||||
|
||||
@Module
|
||||
public abstract class TimetableTabModule {
|
||||
|
||||
@PerChildFragment
|
||||
@Binds
|
||||
abstract TimetableTabContract.Presenter provideTimetableTabPresneter(TimetableTabPresenter timetableTabPresenter);
|
||||
|
||||
@PerChildFragment
|
||||
@Provides
|
||||
static FlexibleAdapter<TimetableHeaderItem> provideTimetableAdapter() {
|
||||
return new FlexibleAdapter<>(null);
|
||||
}
|
||||
}
|
@ -1,4 +1,7 @@
|
||||
package io.github.wulkanowy.ui.main.timetable;
|
||||
package io.github.wulkanowy.ui.main.timetable.tab;
|
||||
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -36,8 +39,8 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(TimetableTabContract.View view) {
|
||||
super.onStart(view);
|
||||
public void attachView(@NonNull TimetableTabContract.View view) {
|
||||
super.attachView(view);
|
||||
getView().showProgressBar(true);
|
||||
getView().showNoItem(false);
|
||||
}
|
||||
@ -62,7 +65,7 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
||||
refreshTask.setOnRefreshListener(this);
|
||||
refreshTask.execute();
|
||||
} else {
|
||||
getView().onNoNetworkError();
|
||||
getView().showNoNetworkMessage();
|
||||
getView().hideRefreshingBar();
|
||||
}
|
||||
}
|
||||
@ -88,7 +91,7 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
||||
|
||||
getView().onRefreshSuccess();
|
||||
} else {
|
||||
getView().onError(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
getView().showMessage(getRepository().getResRepo().getErrorLoginMessage(exception));
|
||||
}
|
||||
getView().hideRefreshingBar();
|
||||
|
||||
@ -177,9 +180,9 @@ public class TimetableTabPresenter extends BasePresenter<TimetableTabContract.Vi
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
public void detachView() {
|
||||
isFirstSight = false;
|
||||
cancelAsyncTasks();
|
||||
super.onDestroy();
|
||||
super.detachView();
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ import android.os.Bundle;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import io.github.wulkanowy.services.jobs.SyncJob;
|
||||
import io.github.wulkanowy.services.notifies.NotificationService;
|
||||
import io.github.wulkanowy.ui.base.BaseActivity;
|
||||
import io.github.wulkanowy.ui.login.LoginActivity;
|
||||
@ -18,16 +18,12 @@ public class SplashActivity extends BaseActivity implements SplashContract.View
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getActivityComponent().inject(this);
|
||||
setButterKnife(ButterKnife.bind(this));
|
||||
|
||||
presenter.onStart(this);
|
||||
presenter.attachView(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
presenter.onDestroy();
|
||||
presenter.detachView();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package io.github.wulkanowy.ui.splash;
|
||||
|
||||
|
||||
import io.github.wulkanowy.di.annotations.PerActivity;
|
||||
import io.github.wulkanowy.ui.base.BaseContract;
|
||||
|
||||
public interface SplashContract {
|
||||
@ -15,7 +13,6 @@ public interface SplashContract {
|
||||
void cancelNotifications();
|
||||
}
|
||||
|
||||
@PerActivity
|
||||
interface Presenter extends BaseContract.Presenter<View> {
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package io.github.wulkanowy.ui.splash;
|
||||
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import io.github.wulkanowy.di.scopes.PerActivity;
|
||||
|
||||
@Module
|
||||
public abstract class SplashModule {
|
||||
|
||||
@PerActivity
|
||||
@Binds
|
||||
abstract SplashContract.Presenter provideSplashPresenter(SplashPresenter splashPresenter);
|
||||
}
|
@ -16,8 +16,8 @@ public class SplashPresenter extends BasePresenter<SplashContract.View>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(@NonNull SplashContract.View activity) {
|
||||
super.onStart(activity);
|
||||
public void attachView(@NonNull SplashContract.View view) {
|
||||
super.attachView(view);
|
||||
getView().cancelNotifications();
|
||||
|
||||
if (getRepository().getSharedRepo().isUserLoggedIn()) {
|
||||
|
@ -12,10 +12,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.WulkanowyApp;
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.data.db.dao.entities.TimetableLesson;
|
||||
import io.github.wulkanowy.data.db.dao.entities.Week;
|
||||
@ -23,22 +20,17 @@ import io.github.wulkanowy.utils.TimeUtils;
|
||||
|
||||
public class TimetableWidgetFactory implements RemoteViewsService.RemoteViewsFactory {
|
||||
|
||||
private Context context;
|
||||
private final Context context;
|
||||
|
||||
private List<TimetableLesson> lessonList = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
RepositoryContract repository;
|
||||
private final RepositoryContract repository;
|
||||
|
||||
public TimetableWidgetFactory(Context context) {
|
||||
public TimetableWidgetFactory(Context context, RepositoryContract repository) {
|
||||
this.context = context;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
private void inject() {
|
||||
if (repository == null) {
|
||||
((WulkanowyApp) context).getApplicationComponent().inject(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@ -47,7 +39,6 @@ public class TimetableWidgetFactory implements RemoteViewsService.RemoteViewsFac
|
||||
|
||||
@Override
|
||||
public void onDataSetChanged() {
|
||||
inject();
|
||||
lessonList = new ArrayList<>();
|
||||
|
||||
if (repository.getSharedRepo().isUserLoggedIn()) {
|
||||
|
@ -11,8 +11,8 @@ import android.widget.RemoteViews;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.AndroidInjection;
|
||||
import io.github.wulkanowy.R;
|
||||
import io.github.wulkanowy.WulkanowyApp;
|
||||
import io.github.wulkanowy.data.RepositoryContract;
|
||||
import io.github.wulkanowy.services.widgets.TimetableWidgetServices;
|
||||
import io.github.wulkanowy.ui.main.MainActivity;
|
||||
@ -26,7 +26,6 @@ public class TimetableWidgetProvider extends AppWidgetProvider {
|
||||
RepositoryContract repository;
|
||||
|
||||
@Override
|
||||
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
inject(context);
|
||||
|
||||
@ -106,7 +105,7 @@ public class TimetableWidgetProvider extends AppWidgetProvider {
|
||||
|
||||
private void inject(Context context) {
|
||||
if (repository == null) {
|
||||
((WulkanowyApp) context.getApplicationContext()).getApplicationComponent().inject(this);
|
||||
AndroidInjection.inject(this, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user