-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MVC #2
Open
florina-muntenescu
wants to merge
4
commits into
master
Choose a base branch
from
mvc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
MVC #2
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
app/src/main/java/upday/mvpvsmvvm/datamodel/IDataModel.java
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
.../upday/mvpvsmvvm/DroidconApplication.java → ...a/upday/patterns/DroidconApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/src/main/java/upday/patterns/datamodel/IDataModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package upday.patterns.datamodel; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
import rx.Observable; | ||
|
||
/** | ||
* The Data Model used by all patterns | ||
*/ | ||
public interface IDataModel { | ||
|
||
/** | ||
* @return a stream of the greeting. The stream will emit once and then complete. | ||
* Allows asynchronous retrieval of the greeting. | ||
*/ | ||
@NonNull | ||
Observable<String> getGreetingAsync(); | ||
|
||
/** | ||
* @return a greeting synchronously. | ||
*/ | ||
@NonNull | ||
String getGreetingSync(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package upday.patterns.mvc; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
/** | ||
* Implementation class for the Controller in the MVC pattern, with a passive model. | ||
*/ | ||
public class Controller { | ||
|
||
@NonNull | ||
private final IView mView; | ||
|
||
public Controller(@NonNull final IView view) { | ||
mView = view; | ||
mView.update(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package upday.patterns.mvc; | ||
|
||
/** | ||
* A view that can update. | ||
*/ | ||
public interface IView { | ||
|
||
void update(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package upday.patterns.mvc; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.widget.TextView; | ||
|
||
import upday.patterns.DroidconApplication; | ||
import upday.patterns.R; | ||
import upday.patterns.datamodel.IDataModel; | ||
|
||
/** | ||
* Implements the view class of the MVC pattern with passive model. | ||
*/ | ||
public class MVCActivity extends AppCompatActivity implements IView { | ||
|
||
@NonNull | ||
private Controller mController; | ||
|
||
@NonNull | ||
private IDataModel mDataModel; | ||
|
||
@Nullable | ||
private TextView mGreetingView; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
mDataModel = getDataModel(); | ||
mController = new Controller(this); | ||
|
||
setupViews(); | ||
} | ||
|
||
private void setupViews() { | ||
mGreetingView = (TextView) findViewById(R.id.greeting); | ||
} | ||
|
||
@Override | ||
public void update() { | ||
assert mGreetingView != null; | ||
mGreetingView.setText(mDataModel.getGreetingSync()); | ||
} | ||
|
||
@NonNull | ||
private IDataModel getDataModel() { | ||
return ((DroidconApplication) getApplication()).getDataModel(); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
.../java/upday/mvpvsmvvm/mvp/IPresenter.java → ...n/java/upday/patterns/mvp/IPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.../main/java/upday/mvpvsmvvm/mvp/IView.java → ...c/main/java/upday/patterns/mvp/IView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package upday.mvpvsmvvm.mvp; | ||
package upday.patterns.mvp; | ||
|
||
import android.support.annotation.NonNull; | ||
|
||
/** | ||
* Interface for the view classes in the MVP pattern. | ||
*/ | ||
public interface IView { | ||
interface IView { | ||
|
||
void setGreeting(@NonNull final String greeting); | ||
} |
8 changes: 4 additions & 4 deletions
8
...java/upday/mvpvsmvvm/mvp/MVPActivity.java → .../java/upday/patterns/mvp/MVPActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<resources> | ||
<string name="app_name">MVP vs MVVM</string> | ||
<string name="app_name">UI Architecture Patterns</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package upday.patterns.mvc; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
/** | ||
* Class that tests the implementation of {@link Controller} | ||
*/ | ||
public class ControllerTest { | ||
|
||
@Mock | ||
private IView mView; | ||
|
||
private Controller mController; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
MockitoAnnotations.initMocks(this); | ||
} | ||
|
||
@Test | ||
public void updateCalled_whenControllerCreated() { | ||
mController = new Controller(mView); | ||
|
||
Mockito.verify(mView).update(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@florina-muntenescu how do you assert on Android ?