Repository: tinmegali/simple-mvp
Branch: master
Commit: df726db3a14d
Files: 42
Total size: 78.3 KB
Directory structure:
gitextract__r8j11ak/
├── AndroidMVP/
│ ├── .idea/
│ │ └── runConfigurations.xml
│ ├── app/
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src/
│ │ ├── androidTest/
│ │ │ └── java/
│ │ │ └── com/
│ │ │ └── tinmegali/
│ │ │ └── androidmvp/
│ │ │ └── ApplicationTest.java
│ │ ├── main/
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── java/
│ │ │ │ └── com/
│ │ │ │ └── tinmegali/
│ │ │ │ └── androidmvp/
│ │ │ │ └── main/
│ │ │ │ ├── MVP_MainActivity.java
│ │ │ │ ├── model/
│ │ │ │ │ └── MainModel.java
│ │ │ │ ├── presenter/
│ │ │ │ │ └── MainPresenter.java
│ │ │ │ └── view/
│ │ │ │ └── MainActivity.java
│ │ │ └── res/
│ │ │ ├── layout/
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── content_main.xml
│ │ │ ├── menu/
│ │ │ │ └── menu_main.xml
│ │ │ ├── values/
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-v21/
│ │ │ │ └── styles.xml
│ │ │ └── values-w820dp/
│ │ │ └── dimens.xml
│ │ └── test/
│ │ └── java/
│ │ └── com/
│ │ └── tinmegali/
│ │ └── androidmvp/
│ │ ├── TestModel.java
│ │ └── TestPresenter.java
│ ├── build.gradle
│ ├── gradle/
│ │ └── wrapper/
│ │ └── gradle-wrapper.properties
│ ├── gradle.properties
│ ├── mvp/
│ │ ├── .gitignore
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src/
│ │ └── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── tinmegali/
│ │ │ └── mvp/
│ │ │ ├── mvp/
│ │ │ │ ├── ActivityView.java
│ │ │ │ ├── ContextView.java
│ │ │ │ ├── GenericMVPActivity.java
│ │ │ │ ├── GenericMVPFragment.java
│ │ │ │ ├── GenericModel.java
│ │ │ │ ├── GenericPresenter.java
│ │ │ │ ├── ModelOps.java
│ │ │ │ ├── PresenterOps.java
│ │ │ │ ├── StateMaintainer.java
│ │ │ │ └── package-info.java
│ │ │ └── util/
│ │ │ └── ActivityKeyBoardDetector.java
│ │ └── res/
│ │ └── values/
│ │ ├── AndroidManifest.xml
│ │ └── strings.xml
│ └── settings.gradle
└── README.md
================================================
FILE CONTENTS
================================================
================================================
FILE: AndroidMVP/.idea/runConfigurations.xml
================================================
* Interface that holds all operations available to MVP layers.
* Controls the communication process between each layer
* interface RequiredViewOps extends ActivityView
* with VIEW methods to be accessed by PRESENTER
*
* interface ProvidedPresenterOps extends PresenterOps
* Operations offered to VIEW to communicate with PRESENTER
*
* interface RequiredPresenterOps
* with Required PRESENTER methods available to MODEL
*
* interface ProvidedModelOps extends ModelOps
* Operations offered to MODEL to communicate with PRESENTER
*
* Created by: Tin Megali on 25/02/16.
* Project: AndroidMVP
* ---------------------------------------------------
* tinmegali.com
*
* framework MVP developed by
*
* Dr. Douglas Schmidth
*
* Layer MODEL from Model View Presenter (MVP) pattern.
* Responsible to deal with all business logic and data in general.
*
* Layer PRESENTER from Model View Presenter (MVP) Pattern.
* Mediates the comunication between layers VIEW and MODEL.
*
* Layer Presenter no padrão Model View Presenter (MVP).
*
* Created by: Tin Megali on 25/02/16.
* Project: AndroidMVP
* ---------------------------------------------------
* tinmegali.com
*
* framework MVP developed by
*
* Dr. Douglas Schmidth
*
RequiredViewOps reference
* RequiredViewOps
* onBackPressed event occurred
* Called by {@link GenericMVPActivity}
*/
@Override
public void onBackPressed() {
}
@Override
public boolean clickClearName() {
return clearName();
}
// For test purposes
public boolean clearName(){
return getModel().clearName();
}
@Override
public boolean clickSaveName(String nameTxt) {
return saveName(nameTxt);
}
// For test purposes
public boolean saveName(String txt){
return getModel().saveName(txt);
}
@Override
public boolean onNameSaved(String nameTxt) {
return nameTxt != null;
}
@Override
public boolean onNameCleared() {
return true;
}
}
================================================
FILE: AndroidMVP/app/src/main/java/com/tinmegali/androidmvp/main/view/MainActivity.java
================================================
package com.tinmegali.androidmvp.main.view;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import com.tinmegali.androidmvp.R;
import com.tinmegali.androidmvp.main.MVP_MainActivity;
import com.tinmegali.androidmvp.main.presenter.MainPresenter;
import com.tinmegali.mvp.mvp.GenericMVPActivity;
/**
* * VIEW layer of MVP pattern. *
* Created by: Tin Megali on 25/02/16.
* Project: AndroidMVP
* ---------------------------------------------------
* tinmegali.com
*
* framework MVP developed by
*
* Dr. Douglas Schmidth
*
* Interface to be implemented by the Activity, * contains some basic common feedback operations *
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
* @see Project's Git
* @see Sample Application
* @see
* Sample MVP interface
*
*/
public interface ActivityView extends ContextView {
/**
* Shows a toast in the Activity with a short time
* @param msg Message to show
*/
void onShowToast(String msg);
/**
* Shows a {@link android.widget.Toast} in the Activity with custom time
* @param msg Message to show
* @param duration Time Length
* {@link android.widget.Toast#LENGTH_SHORT}
* {@link android.widget.Toast#LENGTH_LONG}
*/
void onShowToast(String msg, int duration);
/**
* Shows a Snackbar in Activity with a short time
* @param msg Snackbar message
* @param parentView Snackbar parent view
*/
void onShowSnackbar(String msg, View parentView);
/**
* Shows a Snackbar in Activity with custom time
* @param msg Snackbar message
* @param parentView Snackbar parent view
* @param duration Time Length
* Snackbar#LENGTH_SHORT
* Snackbar#LENGTH_LONG
* Snackbar#LENGTH_INDEFINITE
*/
void onShowSnackbar(String msg, View parentView, int duration);
/**
* Shows a given Snackbar
* Useful for snacks with custom actions.
* @param snackbar The Snackbar to show
*/
void onShowSnackbar(android.support.design.widget.Snackbar snackbar);
}
================================================
FILE: AndroidMVP/mvp/src/main/java/com/tinmegali/mvp/mvp/ContextView.java
================================================
package com.tinmegali.mvp.mvp;
import android.content.Context;
/**
*
Interface that grants access to Contexts
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
* Based on * framework MVP developed by * * Dr. Douglas Schmidth *
* * @see Project's Git
* Generic Abstract Activity.
* Works as a VIEW layer in the MVP pattern.
* Responsible to initialize the PRESENTER and to maintain
* it synchronized with Activity lifecycle changes.
*
* IMPORTANT: View Object should implement RequiredViewOps
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
* Based on * framework MVP developed by * * Dr. Douglas Schmidth *
* * @see Project's GitSnackbar#LENGTH_SHORT
* Snackbar#LENGTH_LONG
*/
public void onShowSnackbar(String msg, View parentView, int duration) {
showSnackbar(msg, parentView, duration);
}
/**
* Show a Snackbar. Helper method to be called by Presenter
* @param snackbar The Snackbar to show
*/
public void onShowSnackbar(Snackbar snackbar) {
showSnackbar(snackbar);
}
}
================================================
FILE: AndroidMVP/mvp/src/main/java/com/tinmegali/mvp/mvp/GenericMVPFragment.java
================================================
package com.tinmegali.mvp.mvp;
import android.content.Context;
import android.util.Log;
import java.lang.ref.WeakReference;
/**
*
* Generic Abstract Fragment.
* Works as a VIEW layer in the MVP pattern.
* Responsible to initialize the PRESENTER and to maintain
* it synchronized with Activity lifecycle changes.
* IMPORTANT: View Object should implement RequiredViewOps
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
Fragment#onCreate(Bundle)
*
* @param opsType PRESENTER Object class
* @param view Interface with VIEW reference to PRESENTER
*/
public void onCreate(Class* Abstract class of MODEL layer on MVP pattern. * Should be extended by any MODEL object. *
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
* Based on * framework MVP developed by * * Dr. Douglas Schmidth *
* * @see Project's GitA Model View Presenter Library using plain and simple interfaces.
* *
* Abstract class of PRESENTER layer on MVP pattern.
* Should be extended by any PRESENTER object
* IMPORTANT: PRESENTER pbject should implement
* RequiredPresenterOps and ProvidedModelOps
*
* IMPORTANT: View Object should implement RequiredViewOps
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
* Based on * framework MVP developed by * * Dr. Douglas Schmidth *
* * @see Project's Git
* Interface implemented by {@link GenericModel}.
* Contains
* initializing and destruction methods called by VIEW layer in
* all MVP objects. Garantes the correct synchronization of MVP
* with Activity lifecycle.
*
* IMPORTANT: View Object should implement RequiredViewOps
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
* Based on * framework MVP developed by * * Dr. Douglas Schmidth *
* * @see Project's Git* Interface implemented by {@link GenericPresenter}. Contains * initializing and destruction methods called by VIEW layer in * the PRESENTER. Garantes the correct synchronization of MVP * with Activity lifecycle. *
*
* IMPORTANT: View Object should implement RequiredViewOps
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
* Based on * framework MVP developed by * * Dr. Douglas Schmidth *
* @see Project's GitRetains and maintain object's state between configuration changes * in Activitys and Fragments. *
*
* IMPORTANT: View Object should implement RequiredViewOps
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
* Based on * framework MVP developed by * * Dr. Douglas Schmidth *
* * @see Project's GitHashMap para salvar os objetos e suas
* chaves de referência.
*/
public static class StateMngFragment extends Fragment {
private HashMap* github.com/tinmegali/simple-mvp *
* * Provides the necessary classes to implement * a Model View Presenter architecture pattern. *
* Each layer of MVP pattern should extends
* its generic object and implement the correct
* interfaces to communicate with the other Layers.
* Check sample MVP interface
*
* sample interface
*
*
*
RequiredViewOps: a interface that you create
* containing VIEW operations
* to be accessed by the PRESENTER
* ProvidedModelOps: a interface that you create
* containing MODEL operations
* to be accessed by the PRESENTER
* RequiredPresenterOps: a interface that you create
* containing PRESENTER operations
* to be accessed by the VIEW
* ProvidedPresenterOps: a interface that you create
* containing PRESENTER operations
* to be accessed by the MODEL
* * Copyright 2016 Tin Megali Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *
*
* Created by Tin Megali on 24/02/16.
* Project: AndroidMVP
*
* www.tinmegali.com
*
* Based on * framework MVP developed by * * Dr. Douglas Schmidth *
*/ package com.tinmegali.mvp.mvp; ================================================ FILE: AndroidMVP/mvp/src/main/java/com/tinmegali/mvp/util/ActivityKeyBoardDetector.java ================================================ package com.tinmegali.mvp.util; import android.graphics.Rect; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import android.view.View; import android.view.ViewTreeObserver; import android.widget.Toast; /** * Created by Tin Megali on 24/02/16.android.widget.Toast in the Activity with custom time
* @param msg Message to show
* @param duration Time Length
* android.widget.Toast#LENGTH_SHORT
* @link android.widget.Toast#LENGTH_LONG
*/
protected void showToast(String msg, final int duration) {
Toast.makeText(
getApplicationContext(), msg, Toast.LENGTH_SHORT
).show();
}
/**
* Shows a Snackbar in Activity with a short time
* @param msg Snackbar message
* @param view Snackbar parent view
*/
protected void showSnackbar(String msg, View view){
android.support.design.widget.Snackbar.make(view, msg, android.support.design.widget.Snackbar.LENGTH_SHORT).show();
}
/**
* Shows a Snackbar in Activity with custom time
* @param msg Snackbar message
* @param view Snackbar parent view
* @param duration Time Length
* Snackbar#LENGTH_SHORT
* Snackbar#LENGTH_LONG
* Snackbar#LENGTH_INDEFINITE
*/
protected void showSnackbar(String msg, View view, int duration){
android.support.design.widget.Snackbar.make( view, msg, duration).show();
}
/**
* Shows a given Snackbar
* Useful for snacks with custom actions.
* @param snackbar The Snackbar to show
*/
protected void showSnackbar(android.support.design.widget.Snackbar snackbar){
snackbar.show();
}
/**
* Detecting Layout Root changes
* A Model View Presenter Library using plain and simple interfaces, based on concept from Dr. Douglas Schmidt
Attention:
simple-mvp is still an experimental library created for education purposes.
Some methods and operations may change until its maturity.
Created by Tin Megali
compile 'com.tinmegali.mvp:mvp:0.0.7'
interface RequiredViewOps extends ActivityView
interface ProvidedPresenterOps extends PresenterOps
interface RequiredPresenterOps
interface ProvidedModelOps extends ModelOps
class MODEL
extends GenericModel
implements MVP_MainActivity.ProvidedModelOps
class VIEW_Activity extends GenericMVPActivity
implements MVP_MainActivity.RequiredViewOps
GenericMVPFragment
class MainPresenter extends GenericPresenter
implements
MVP_MainActivity.RequiredPresenterOps,
MVP_MainActivity.ProvidedPresenterOps
RequiredViewOps fornece métodos para Presenter
comunicar com View. É necessário extender ActivityView
ProvidedPresenterOps fornece operações oferecidas
ao layer View para comunicação com Presenter.
É preciso extender PresenterOps
RequiredPresenterOps operações oferecidas
pelo layer Presenter para comunicações com Model
ProvidedModelOps operações oferecidos pelo
layer Model para comunicações com Presenter.
É preciso extender ModelOps
Model extendendo GenericModel
e implementando ProvidedModelOps
ex: {@link com.tinmegali.androidmvp.main.model.MainModel}
Presenter extendendo GenericPresenter,
implementando RequiredPresenterOps e ProvidedPresenterOps.
exemplo: {@link com.tinmegali.androidmvp.main.presenter.MainPresenter}
View GenericMVPActivity ou GenericMVPFragment e
implementando RequiredViewOps
Exemplo: {@link com.tinmegali.androidmvp.main.view.MainActivity}