Skip to content

Commit

Permalink
Adding conductor sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Yotive committed Dec 31, 2016
1 parent 4158395 commit 7511156
Show file tree
Hide file tree
Showing 14 changed files with 494 additions and 29 deletions.
1 change: 1 addition & 0 deletions codemash_common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
// -- Dagger 2
compile 'com.google.dagger:dagger:2.8'
annotationProcessor 'com.google.dagger:dagger-compiler:2.8'
androidTestAnnotationProcessor 'com.google.dagger:dagger-compiler:2.8'

// -- Retrofit 2
compile 'com.squareup.retrofit2:retrofit:2.1.0'
Expand Down
13 changes: 0 additions & 13 deletions conductor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@ dependencies {
// If you want the components that go along with
// Android's support libraries (currently just a PagerAdapter):
compile 'com.bluelinelabs:conductor-support:2.0.4'
// If you want RxJava/RxAndroid lifecycle support:
compile 'com.bluelinelabs:conductor-rxlifecycle:2.0.4'

// RxAndroid
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'

// RxLifecycle
compile 'com.trello:rxlifecycle:1.0'
// If you want to bind to Android-specific lifecycles
compile 'com.trello:rxlifecycle-android:1.0'
// If you want pre-written Activities and Fragments you can subclass as providers
compile 'com.trello:rxlifecycle-components:1.0'

// Dagger 2
compile 'com.google.dagger:dagger:2.8'
Expand Down
5 changes: 4 additions & 1 deletion conductor/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<uses-permission android:name="android.permission.INTERNET" />

<application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
android:label="@string/app_name"
android:supportsRtl="true"
android:name="com.example.myotive.codemash_common.BaseApplication"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.myotive.conductor;

import android.support.v7.app.ActionBar;

/**
* Created by michaelyotive_hr on 12/31/16.
*/

public interface ActionBarProvider {
ActionBar getSupportActionBar();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,68 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ProgressBar;

public class MainActivity extends AppCompatActivity {
import com.bluelinelabs.conductor.ChangeHandlerFrameLayout;
import com.bluelinelabs.conductor.Conductor;
import com.bluelinelabs.conductor.Router;
import com.bluelinelabs.conductor.RouterTransaction;
import com.example.myotive.codemash_common.BaseApplication;
import com.example.myotive.codemash_common.network.CodeMashAPI;
import com.example.myotive.conductor.controllers.SpeakerListController;

public class MainActivity extends AppCompatActivity implements ProgressBarProvider, ActionBarProvider {

private ChangeHandlerFrameLayout mainContent;
private ProgressBar progressBar;
private Router router;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mainContent = (ChangeHandlerFrameLayout)findViewById(R.id.main_content);
progressBar = (ProgressBar)findViewById(R.id.loading);

router = Conductor.attachRouter(this, mainContent, savedInstanceState);
if (!router.hasRootController()) {
CodeMashAPI codeMashAPI = BaseApplication.getApplication(this)
.getApplicationComponent()
.CodeMashAPI();
router.setRoot(RouterTransaction.with(new SpeakerListController(codeMashAPI)));
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
onBackPressed();
return true;
}

return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
if (!router.handleBack()) {
super.onBackPressed();
}
}

@Override
public void showProgressBar() {
mainContent.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE);
}

@Override
public void hideProgressBar() {
mainContent.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.myotive.conductor;

/**
* Created by michaelyotive_hr on 12/31/16.
*/

public interface ProgressBarProvider {
void showProgressBar();
void hideProgressBar();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.example.myotive.conductor.animation;

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.bluelinelabs.conductor.changehandler.AnimatorChangeHandler;
import com.example.myotive.conductor.R;

/**
* Created by michaelyotive_hr on 12/31/16.
*/

public class ControllerTransistionHandler extends AnimatorChangeHandler {
@NonNull
@Override
protected Animator getAnimator(@NonNull ViewGroup container, @Nullable View from, @Nullable View to, boolean isPush, boolean toAddedToContainer) {
//container.getContext().getResources().getAnimation();
Animation slideIn = AnimationUtils.loadAnimation(container.getContext(), R.anim.slide_in_right);
Animation slideOut = AnimationUtils.loadAnimation(container.getContext(), R.anim.slide_out_right);

if(isPush){
// to == enter
if(to != null){
to.startAnimation(slideIn);
}

if(from != null){
from.startAnimation(slideOut);
}
}
else{
// to == pop
if(to != null){
to.startAnimation(slideOut);
}

if(from != null){
from.startAnimation(slideIn);
}
}

return new AnimatorSet();
}

@Override
protected void resetFromView(@NonNull View from) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.example.myotive.conductor.controllers;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bluelinelabs.conductor.Controller;
import com.example.myotive.conductor.ActionBarProvider;
import com.example.myotive.conductor.ProgressBarProvider;

/**
* Created by michaelyotive_hr on 12/31/16.
*/

public class BaseController extends Controller {

public BaseController() {

}

public BaseController(Bundle bundle){
super(bundle);
}

@NonNull
@Override
protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
return null;
}

private ActionBar getActionBar() {
ActionBarProvider actionBarProvider = ((ActionBarProvider)getActivity());
return actionBarProvider != null ? actionBarProvider.getSupportActionBar() : null;
}

void setActionBarTitle(String title){
ActionBar actionBar = getActionBar();
if(actionBar != null){
actionBar.setTitle(title);
}
}

void setDisplayHomeAsUpEnabled(boolean enabled){
ActionBar actionBar = getActionBar();
if(actionBar != null){
actionBar.setDisplayHomeAsUpEnabled(enabled);
}
}

private ProgressBarProvider getProgressBarProvider(){
return ((ProgressBarProvider)getActivity());
}

void showProgressBar(){
ProgressBarProvider progressBarProvider = getProgressBarProvider();
if(progressBarProvider != null){
progressBarProvider.showProgressBar();
}
}

void hideProgressBar(){
ProgressBarProvider progressBarProvider = getProgressBarProvider();
if(progressBarProvider != null){
progressBarProvider.hideProgressBar();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.example.myotive.conductor.controllers;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.myotive.codemash_common.network.models.Speaker;
import com.example.myotive.codemash_common.ui.RoundedTransformation;
import com.example.myotive.codemash_common.utility.ConversionUtility;
import com.example.myotive.conductor.R;
import com.squareup.picasso.Picasso;

/**
* Created by michaelyotive_hr on 12/30/16.
*/

public class SpeakerDetailController extends BaseController {

private Speaker speaker;
private ImageView speakerImage;
private TextView speakerBio;

// Required constructor to restore instance state
public SpeakerDetailController(Bundle args){
super(args);
}


// Constructor Injection allowed with Conductor as long as you have
// default constructor
public SpeakerDetailController(Speaker speaker){
this.speaker = speaker;
}


@NonNull
@Override
protected View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {

View view = inflater.inflate(R.layout.controller_speaker_detail, container, false);


speakerImage = (ImageView)view.findViewById(R.id.detail_profile_image);
if(!TextUtils.isEmpty(speaker.getGravatarUrl())){

String gravatarUrl = speaker.getGravatarUrl();
// As of 12/4, the gravatar URL is missing the protocol and that makes Picasso sad.
if(!speaker.getGravatarUrl().contains("http")){
gravatarUrl = "http:" + speaker.getGravatarUrl();
}

int speakerProfileSize = ConversionUtility.dpToPx(225, getActivity());
int radius = speakerProfileSize / 2;
gravatarUrl = gravatarUrl + "?size=" + String.valueOf(speakerProfileSize);

Picasso.with(getActivity())
.load(gravatarUrl)
.transform(new RoundedTransformation(radius, 4))
.placeholder(com.example.myotive.codemash_common.R.drawable.codemash_gearhead)
.into(speakerImage);
}
else{
Picasso.with(getActivity())
.load(com.example.myotive.codemash_common.R.drawable.codemash_gearhead)
.into(speakerImage);
}

speakerBio = (TextView)view.findViewById(R.id.detail_profile_bio);
speakerBio.setText(speaker.getBiography());

return view;
}

@Override
protected void onAttach(@NonNull View view) {
super.onAttach(view);
setActionBarTitle(speaker.getFullName());
setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean handleBack() {
return super.handleBack();
}
}
Loading

0 comments on commit 7511156

Please sign in to comment.