Code refactoring

This commit is contained in:
Tariel Hlontsi 2016-04-29 15:25:02 +03:00
parent d68c669396
commit 03272e0712
5 changed files with 21 additions and 18 deletions

View File

@ -42,8 +42,8 @@ public class DetailModel implements Model.Detail {
presenter = null; presenter = null;
} }
} }
@Override
public void sendMessage(String message) { private void sendMessage(String message) {
presenter.showMessage(message); presenter.showMessage(message);
} }

View File

@ -109,8 +109,8 @@ public class ItemModel implements Model.Item {
presenter = null; presenter = null;
} }
} }
@Override
public void sendMessage(String message) { private void sendMessage(String message) {
presenter.showMessage(message); presenter.showMessage(message);
} }
// events <-- // events <--

View File

@ -18,7 +18,6 @@ public interface Model {
void onDestroy(boolean isConfigurationChanging); void onDestroy(boolean isConfigurationChanging);
void executeQuery(); void executeQuery();
void notifyDataSetChanged(); void notifyDataSetChanged();
void sendMessage(String message);
void onEvent(Message event); void onEvent(Message event);
} }
@ -28,9 +27,9 @@ public interface Model {
int getSetsCount(); int getSetsCount();
void setPresenter(Presenter.SetList presenter); void setPresenter(Presenter.SetList presenter);
Presenter.SetList getPresenter(); Presenter.SetList getPresenter();
//GLM //GLM
List<hikapro.com.backpack.model.entities.Set> getSet(); List<hikapro.com.backpack.model.entities.Set> getSets(); // tag renamed
void setsReorderNotify();
} }
interface Item extends Base { interface Item extends Base {

View File

@ -66,8 +66,8 @@ public class SetModel implements Model.Set {
presenter.notifyDataSetChanged(); presenter.notifyDataSetChanged();
} }
@Override
public void sendMessage(String message) { private void sendMessage(String message) {
presenter.showMessage(message); presenter.showMessage(message);
} }
@ -104,6 +104,14 @@ public class SetModel implements Model.Set {
break; break;
} }
} }
@Override
public void setsReorderNotify() {
Message command = Message.obtain();
command.what = Command.SET_REORDER;
command.obj = cache;
dao.executeCommand(command);
}
//endregion //endregion
//region other //region other
@ -124,8 +132,8 @@ public class SetModel implements Model.Set {
//GLM //GLM
@Override @Override
public List<hikapro.com.backpack.model.entities.Set> getSet() public List<hikapro.com.backpack.model.entities.Set> getSets()
{ {
return iList; return cache;
} }
} }

View File

@ -2,14 +2,11 @@ package hikapro.com.backpack.presenter;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper; import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.DragEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast; import android.widget.Toast;
@ -17,14 +14,12 @@ import java.lang.ref.WeakReference;
import java.util.Collections; import java.util.Collections;
import hikapro.com.backpack.R; import hikapro.com.backpack.R;
import hikapro.com.backpack.model.SetModel;
import hikapro.com.backpack.model.Model; import hikapro.com.backpack.model.Model;
import hikapro.com.backpack.model.entities.Set; import hikapro.com.backpack.model.entities.Set;
import hikapro.com.backpack.presenter.adapters.SetListAdapter; import hikapro.com.backpack.presenter.adapters.SetListAdapter;
import hikapro.com.backpack.presenter.adapters.helper.OnStartDragListener; import hikapro.com.backpack.presenter.adapters.helper.OnStartDragListener;
import hikapro.com.backpack.presenter.adapters.helper.SimpleItemTouchHelperCallback; import hikapro.com.backpack.presenter.adapters.helper.SimpleItemTouchHelperCallback;
import hikapro.com.backpack.view.View; import hikapro.com.backpack.view.View;
import hikapro.com.backpack.view.fragments.SetListFragment;
import hikapro.com.backpack.view.recycler.SetViewHolder; import hikapro.com.backpack.view.recycler.SetViewHolder;
/** /**
@ -51,15 +46,16 @@ public class SetListPresenter implements Presenter.SetList {
//GLM_add_resources_SetList //GLM_add_resources_SetList
@Override @Override
public void onItemDismiss(int position) { public void onItemDismiss(int position) {
model.getSet().remove(position); model.getSets().remove(position);
adapter.notifyItemRemoved(position); adapter.notifyItemRemoved(position);
} }
//GLM_add_resources_SetList //GLM_add_resources_SetList
@Override @Override
public boolean onItemMove(int fromPosition, int toPosition) { public boolean onItemMove(int fromPosition, int toPosition) {
Collections.swap(model.getSet(), fromPosition, toPosition); Collections.swap(model.getSets(), fromPosition, toPosition);
adapter.notifyItemMoved(fromPosition, toPosition); adapter.notifyItemMoved(fromPosition, toPosition);
model.setsReorderNotify();
return true; return true;
} }