Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #49 from grandcentrix/feature/composite_fragments
Browse files Browse the repository at this point in the history
TiFragmentPlugin
  • Loading branch information
StefMa authored Jan 9, 2017
2 parents a1886de + 20e3b22 commit e026ec5
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 3 deletions.
1 change: 1 addition & 0 deletions plugin-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {

compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.pascalwelsch.compositeandroid:activity:$supportLibraryVersion"
compile "com.pascalwelsch.compositeandroid:fragment:$supportLibraryVersion"

androidTestCompile "com.android.support:appcompat-v7:$supportLibraryVersion"
androidTestCompile 'com.android.support.test:runner:0.5';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import android.app.Activity;
import android.app.Instrumentation;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
Expand Down Expand Up @@ -48,6 +47,9 @@ public void startTestActivity() throws Exception {
Espresso.onView(withId(R.id.helloworld_text))
.check(matches(allOf(isDisplayed(), withText("Hello World 1"))));

Espresso.onView(withId(R.id.fragment_helloworld_text))
.check(matches(allOf(isDisplayed(), withText("Hello World 1"))));

activity.finish();
}

Expand All @@ -64,6 +66,8 @@ public void testFullLifecycleIncludingConfigurationChange() throws Throwable {
// make sure the attached presenter filled the UI
Espresso.onView(withId(R.id.helloworld_text))
.check(matches(allOf(isDisplayed(), withText("Hello World 1"))));
Espresso.onView(withId(R.id.fragment_helloworld_text))
.check(matches(allOf(isDisplayed(), withText("Hello World 1"))));

// restart the activity
rotateOrientation(activity);
Expand All @@ -72,6 +76,8 @@ public void testFullLifecycleIncludingConfigurationChange() throws Throwable {
// correctly
Espresso.onView(withId(R.id.helloworld_text))
.check(matches(allOf(isDisplayed(), withText("Hello World 2"))));
Espresso.onView(withId(R.id.fragment_helloworld_text))
.check(matches(allOf(isDisplayed(), withText("Hello World 2"))));

activity.finish();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {

setContentView(R.layout.activity_test);
mText = (TextView) findViewById(R.id.helloworld_text);

if (savedInstanceState == null) {

final TestFragment testFragment = new TestFragment();

getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_container, testFragment)
.commit();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2017 grandcentrix GmbH
* 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.
*/

package net.grandcentrix.thirtyinch.plugin_test;


import com.pascalwelsch.compositeandroid.fragment.CompositeFragment;

import net.grandcentrix.thirtyinch.internal.TiPresenterProvider;
import net.grandcentrix.thirtyinch.plugin.TiFragmentPlugin;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class TestFragment extends CompositeFragment implements TestView {

private TextView mTextView;

public TestFragment() {
addPlugin(new TiFragmentPlugin<>(new TiPresenterProvider<TestPresenter>() {
@NonNull
@Override
public TestPresenter providePresenter() {
return new TestPresenter();
}
}));
}

@Nullable
@Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container,
@Nullable final Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
final View rootView = inflater.inflate(R.layout.fragment_test, container, false);
mTextView = (TextView) rootView.findViewById(R.id.fragment_helloworld_text);
return rootView;
}

@Override
public void showText(final String s) {
mTextView.setText(s);
}
}
10 changes: 8 additions & 2 deletions plugin-test/src/main/res/layout/activity_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

<TextView
android:id="@+id/helloworld_text"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:gravity="center" />

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp" />

</LinearLayout>
13 changes: 13 additions & 0 deletions plugin-test/src/main/res/layout/fragment_test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/fragment_helloworld_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />

</LinearLayout>
1 change: 1 addition & 0 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ android {
dependencies {
compile project(':thirtyinch')
provided "com.pascalwelsch.compositeandroid:activity:$supportLibraryVersion"
provided "com.pascalwelsch.compositeandroid:fragment:$supportLibraryVersion"
}

publish {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@

import java.util.List;

/**
* Binds a {@link TiPresenter} to an {@link Activity}
*
* @param <P> {@link TiPresenter} with will be attached
* @param <V> View, expected by the {@link TiPresenter}
*/
public class TiActivityPlugin<P extends TiPresenter<V>, V extends TiView> extends ActivityPlugin
implements TiViewProvider<V>, DelegatedTiActivity<P>, TiLoggingTagProvider,
InterceptableViewBinder<V> {
Expand Down
Loading

0 comments on commit e026ec5

Please sign in to comment.