Skip to content

Commit

Permalink
✈️ update template fragment.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jedsada Tiwongvorakul committed May 7, 2017
1 parent ca24ec3 commit e9a4bd6
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.wisdomlanna.www.dagger2_mvp_example;

import com.wisdomlanna.www.dagger2_mvp_example.template.activity.CustomActivity;
import com.wisdomlanna.www.dagger2_mvp_example.ui.MainActivity;
import com.wisdomlanna.www.dagger2_mvp_example.module.AndroidModule;
import com.wisdomlanna.www.dagger2_mvp_example.module.ApiModule;
import com.wisdomlanna.www.dagger2_mvp_example.module.NetworkModule;
import com.wisdomlanna.www.dagger2_mvp_example.module.UtilModule;
import com.wisdomlanna.www.dagger2_mvp_example.template.activity.CustomActivity;
import com.wisdomlanna.www.dagger2_mvp_example.template.frangment.CustomFragment;
import com.wisdomlanna.www.dagger2_mvp_example.ui.MainActivity;

import javax.inject.Singleton;

Expand All @@ -19,4 +20,6 @@ public interface ApplicationComponent {
void inject(MainActivity mainActivity);

void inject(CustomActivity customActivity);

void inject(CustomFragment customFragment);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.wisdomlanna.www.dagger2_mvp_example.template.activity;

import android.os.Bundle;

import com.wisdomlanna.www.dagger2_mvp_example.ApplicationComponent;
import com.wisdomlanna.www.dagger2_mvp_example.ui.base.BaseActivity;

public class CustomActivity extends BaseActivity<CustomPresenter> implements CustomInterface.View {
public class CustomActivity extends BaseActivity<CustomActivityPresenter>
implements CustomActivityInterface.View {
@Override
public void testResult() {

Expand All @@ -20,12 +23,12 @@ protected void doInjection(ApplicationComponent component) {
}

@Override
protected void startActivity() {
protected void startView() {

}

@Override
protected void stopActivity() {
protected void stopView() {

}

Expand All @@ -48,4 +51,14 @@ protected void setupView() {
protected void initialize() {

}

@Override
protected void saveInstanceState(Bundle outState) {

}

@Override
public void restoreView(Bundle savedInstanceState) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.wisdomlanna.www.dagger2_mvp_example.ui.base.BaseInterface;

class CustomInterface {
class CustomActivityInterface {

interface View extends BaseInterface.View {
void testResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import javax.inject.Inject;

class CustomPresenter extends BasePresenter<CustomInterface.View> implements CustomInterface.Presenter {
class CustomActivityPresenter extends BasePresenter<CustomActivityInterface.View> implements CustomActivityInterface.Presenter {

@Inject
CustomPresenter() {
CustomActivityPresenter() {
super();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,94 @@
package com.wisdomlanna.www.dagger2_mvp_example.template.frangment;

public class CustomFragment {
}
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.wisdomlanna.www.dagger2_mvp_example.ApplicationComponent;
import com.wisdomlanna.www.dagger2_mvp_example.R;
import com.wisdomlanna.www.dagger2_mvp_example.Utils;
import com.wisdomlanna.www.dagger2_mvp_example.ui.base.BaseFragment;

import javax.inject.Inject;

import butterknife.BindView;
import timber.log.Timber;

public class CustomFragment extends BaseFragment<CustomFragmentPresenter>
implements CustomFragmentInterface.View {

@Inject
Utils utils;

@BindView(R.id.tv_test)
TextView tvTest;
private int number;

public static CustomFragment newInstance() {
CustomFragment fragment = new CustomFragment();
Bundle bundle = new Bundle();
fragment.setArguments(bundle);
return fragment;
}

@SuppressLint("DefaultLocale")
@Override
public void testResult() {
Timber.d("status network : %b", utils.isNetworkAvailable());
tvTest.setText(String.format("test : %d", number));
}

@Override
protected int layoutToInflate() {
return R.layout.custom_fragment;
}

@Override
protected void doInjection(ApplicationComponent component) {
component.inject(CustomFragment.this);
}

@Override
protected void startView() {

}

@Override
protected void stopView() {

}

@Override
protected void bindView(View view) {

}

@Override
protected void setupInstance() {

}

@Override
protected void setupView() {

}

@Override
protected void initialize() {
Timber.d("initialize");
number = 5555;
getPresenter().testFragment();
}

@Override
protected void saveInstanceState(Bundle outState) {
outState.putInt("number", number);
}

@Override
public void restoreView(Bundle savedInstanceState) {
number = savedInstanceState.getInt("number");
testResult();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.wisdomlanna.www.dagger2_mvp_example.template.frangment;

import com.wisdomlanna.www.dagger2_mvp_example.ui.base.BaseInterface;

class CustomFragmentInterface {

interface View extends BaseInterface.View {
void testResult();
}

interface Presenter {
void testFragment();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.wisdomlanna.www.dagger2_mvp_example.template.frangment;

import com.wisdomlanna.www.dagger2_mvp_example.ui.base.BasePresenter;

import javax.inject.Inject;

class CustomFragmentPresenter extends BasePresenter<CustomFragmentInterface.View>
implements CustomFragmentInterface.Presenter {

@Inject
CustomFragmentPresenter() {
super();
}

@Override
public void onViewCreate() {

}

@Override
public void onViewDestroy() {

}

@Override
public void onViewStart() {

}

@Override
public void onViewStop() {

}

@Override
public void testFragment() {
getView().testResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.wisdomlanna.www.dagger2_mvp_example.R;
import com.wisdomlanna.www.dagger2_mvp_example.R2;
import com.wisdomlanna.www.dagger2_mvp_example.api.dao.UserInfoDao;
import com.wisdomlanna.www.dagger2_mvp_example.template.frangment.CustomFragment;
import com.wisdomlanna.www.dagger2_mvp_example.ui.base.BaseActivity;
import com.wisdomlanna.www.dagger2_mvp_example.ui.event.TestBusEvent;

Expand Down Expand Up @@ -69,13 +70,13 @@ protected void doInjection(ApplicationComponent component) {
}

@Override
protected void startActivity() {
protected void startView() {
Timber.d("start activity");
getPresenter().onViewStart();
}

@Override
protected void stopActivity() {
protected void stopView() {
Timber.d("stop activity");
getPresenter().onViewStop();
}
Expand All @@ -98,20 +99,21 @@ protected void setupView() {

@Override
protected void initialize() {
getSupportFragmentManager().beginTransaction()
.add(R.id.container_fragment, CustomFragment.newInstance())
.commit();
getPresenter().loadUserInfo("pondthaitay");
getPresenter().plus("5", "5");
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
protected void saveInstanceState(Bundle outState) {
outState.putInt("result", result);
outState.putParcelable("user_info_dao", Parcels.wrap(userInfoDao));
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
public void restoreView(Bundle savedInstanceState) {
result = savedInstanceState.getInt("result");
userInfoDao = Parcels.unwrap(savedInstanceState.getParcelable("user_info_dao"));
if (userInfoDao == null) getPresenter().loadUserInfo("pondthaitay");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public abstract class BaseActivity<P extends BasePresenter> extends AppCompatAct

protected abstract void doInjection(final ApplicationComponent component);

protected abstract void startActivity();
protected abstract void startView();

protected abstract void stopActivity();
protected abstract void stopView();

protected abstract void bindView();

Expand All @@ -49,6 +49,10 @@ public abstract class BaseActivity<P extends BasePresenter> extends AppCompatAct

protected abstract void initialize();

protected abstract void saveInstanceState(Bundle outState);

public abstract void restoreView(Bundle savedInstanceState);

@SuppressWarnings("unchecked")
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -66,12 +70,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (savedInstanceState == null) initialize();
}

private void setupProgressDialog() {
progressDialog = new ProgressDialog(this);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(getResources().getString(R.string.loading));
}

@Override
public P getPresenter() {
if (presenter != null) return presenter;
throw new MvpPresenterNotCreateException();
Expand Down Expand Up @@ -115,23 +114,25 @@ public void unAuthorizedApi() {
@Override
protected void onStart() {
super.onStart();
startActivity();
startView();
}

@Override
protected void onStop() {
super.onStop();
stopActivity();
stopView();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
saveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
restoreView(savedInstanceState);
}

@Override
Expand All @@ -142,6 +143,12 @@ protected void onDestroy() {
presenter.detachView();
}

private void setupProgressDialog() {
progressDialog = new ProgressDialog(this);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(getResources().getString(R.string.loading));
}

private void showSnackBar(@NonNull String message) {
if (contentView != null) Snackbar.make(contentView, message, Snackbar.LENGTH_SHORT).show();
}
Expand Down
Loading

0 comments on commit e9a4bd6

Please sign in to comment.