Skip to content

Commit

Permalink
Merge branch 'support_design_library'
Browse files Browse the repository at this point in the history
  • Loading branch information
frogermcs committed Jul 22, 2015
2 parents e631f70 + ef82e00 commit d14fba8
Show file tree
Hide file tree
Showing 27 changed files with 540 additions and 942 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
compile 'com.android.support:palette-v7:22.+'
compile 'com.android.support:recyclerview-v7:22.+'
compile 'com.android.support:cardview-v7:22.+'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:design:22.2.1'

compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.jakewharton.timber:timber:2.5.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
package io.github.froger.instamaterial.ui.activity;

import android.os.Handler;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.Optional;
import io.github.froger.instamaterial.ui.utils.DrawerLayoutInstaller;
import io.github.froger.instamaterial.R;
import io.github.froger.instamaterial.Utils;
import io.github.froger.instamaterial.ui.view.GlobalMenuView;

/**
* Created by Miroslaw Stanek on 19.01.15.
*/
public class BaseActivity extends AppCompatActivity implements GlobalMenuView.OnHeaderClickListener {
public class BaseActivity extends AppCompatActivity {

@Optional
@InjectView(R.id.toolbar)
Expand All @@ -33,16 +25,20 @@ public class BaseActivity extends AppCompatActivity implements GlobalMenuView.On
ImageView ivLogo;

private MenuItem inboxMenuItem;
private DrawerLayout drawerLayout;

@Override
public void setContentView(int layoutResID) {
super.setContentView(layoutResID);
injectViews();
}

protected void injectViews() {
ButterKnife.inject(this);
setupToolbar();
if (shouldInstallDrawer()) {
setupDrawer();
}
}

public void setContentViewWithoutInject(int layoutResId) {
super.setContentView(layoutResId);
}

protected void setupToolbar() {
Expand All @@ -52,22 +48,6 @@ protected void setupToolbar() {
}
}

protected boolean shouldInstallDrawer() {
return true;
}

private void setupDrawer() {
GlobalMenuView menuView = new GlobalMenuView(this);
menuView.setOnHeaderClickListener(this);

drawerLayout = DrawerLayoutInstaller.from(this)
.drawerRoot(R.layout.drawer_root)
.drawerLeftView(menuView)
.drawerLeftWidth(Utils.dpToPx(300))
.withNavigationIconToggler(getToolbar())
.build();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
Expand All @@ -87,19 +67,4 @@ public MenuItem getInboxMenuItem() {
public ImageView getIvLogo() {
return ivLogo;
}

@Override
public void onGlobalMenuHeaderClick(final View v) {
drawerLayout.closeDrawer(Gravity.START);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
int[] startingLocation = new int[2];
v.getLocationOnScreen(startingLocation);
startingLocation[0] += v.getWidth() / 2;
UserProfileActivity.startUserProfileFromLocation(startingLocation, BaseActivity.this);
overridePendingTransition(0, 0);
}
}, 200);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package io.github.froger.instamaterial.ui.activity;

import android.os.Handler;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

import butterknife.InjectView;
import butterknife.OnClick;
import io.github.froger.instamaterial.R;
import io.github.froger.instamaterial.ui.utils.CircleTransformation;

/**
* Created by Miroslaw Stanek on 15.07.15.
*/
public class BaseDrawerActivity extends BaseActivity {

@InjectView(R.id.drawerLayout)
DrawerLayout drawerLayout;
@InjectView(R.id.ivMenuUserProfilePhoto)
ImageView ivMenuUserProfilePhoto;

private int avatarSize;
private String profilePhoto;

@Override
public void setContentView(int layoutResID) {
super.setContentViewWithoutInject(R.layout.activity_drawer);
ViewGroup viewGroup = (ViewGroup) findViewById(R.id.flContentRoot);
LayoutInflater.from(this).inflate(layoutResID, viewGroup, true);
injectViews();

setupHeader();
}

@Override
protected void setupToolbar() {
super.setupToolbar();
if (getToolbar() != null) {
getToolbar().setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawerLayout.openDrawer(Gravity.LEFT);
}
});
}
}

@OnClick(R.id.vGlobalMenuHeader)
public void onGlobalMenuHeaderClick(final View v) {
drawerLayout.closeDrawer(Gravity.LEFT);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
int[] startingLocation = new int[2];
v.getLocationOnScreen(startingLocation);
startingLocation[0] += v.getWidth() / 2;
UserProfileActivity.startUserProfileFromLocation(startingLocation, BaseDrawerActivity.this);
overridePendingTransition(0, 0);
}
}, 200);
}

private void setupHeader() {
this.avatarSize = getResources().getDimensionPixelSize(R.dimen.global_menu_avatar_size);
this.profilePhoto = getResources().getString(R.string.user_profile_photo);
Picasso.with(this)
.load(profilePhoto)
.placeholder(R.drawable.img_circle_placeholder)
.resize(avatarSize, avatarSize)
.centerCrop()
.transform(new CircleTransformation())
.into(ivMenuUserProfilePhoto);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
import android.widget.LinearLayout;

import butterknife.InjectView;
import io.github.froger.instamaterial.ui.adapter.CommentsAdapter;
import io.github.froger.instamaterial.R;
import io.github.froger.instamaterial.Utils;
import io.github.froger.instamaterial.ui.adapter.CommentsAdapter;
import io.github.froger.instamaterial.ui.view.SendCommentButton;

/**
* Created by froger_mcs on 11.11.14.
*/
public class CommentsActivity extends BaseActivity implements SendCommentButton.OnSendClickListener {
public class CommentsActivity extends BaseDrawerActivity implements SendCommentButton.OnSendClickListener {
public static final String ARG_DRAWING_START_LOCATION = "arg_drawing_start_location";

@InjectView(R.id.contentRoot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.View;
import android.view.animation.OvershootInterpolator;
import android.widget.ImageButton;

import butterknife.InjectView;
import butterknife.OnClick;
Expand All @@ -21,7 +23,7 @@
import io.github.froger.instamaterial.ui.view.FeedContextMenuManager;


public class MainActivity extends BaseActivity implements FeedAdapter.OnFeedItemClickListener,
public class MainActivity extends BaseDrawerActivity implements FeedAdapter.OnFeedItemClickListener,
FeedContextMenu.OnFeedContextMenuItemClickListener {
public static final String ACTION_SHOW_LOADING_ITEM = "action_show_loading_item";

Expand All @@ -31,7 +33,9 @@ public class MainActivity extends BaseActivity implements FeedAdapter.OnFeedItem
@InjectView(R.id.rvFeed)
RecyclerView rvFeed;
@InjectView(R.id.btnCreate)
ImageButton btnCreate;
FloatingActionButton fabCreate;
@InjectView(R.id.content)
CoordinatorLayout clContent;

private FeedAdapter feedAdapter;

Expand Down Expand Up @@ -99,7 +103,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
}

private void startIntroAnimation() {
btnCreate.setTranslationY(2 * getResources().getDimensionPixelOffset(R.dimen.btn_fab_size));
fabCreate.setTranslationY(2 * getResources().getDimensionPixelOffset(R.dimen.btn_fab_size));

int actionbarSize = Utils.dpToPx(56);
getToolbar().setTranslationY(-actionbarSize);
Expand Down Expand Up @@ -128,7 +132,7 @@ public void onAnimationEnd(Animator animation) {
}

private void startContentAnimation() {
btnCreate.animate()
fabCreate.animate()
.translationY(0)
.setInterpolator(new OvershootInterpolator(1.f))
.setStartDelay(300)
Expand Down Expand Up @@ -184,9 +188,13 @@ public void onCancelClick(int feedItem) {
@OnClick(R.id.btnCreate)
public void onTakePhotoClick() {
int[] startingLocation = new int[2];
btnCreate.getLocationOnScreen(startingLocation);
startingLocation[0] += btnCreate.getWidth() / 2;
fabCreate.getLocationOnScreen(startingLocation);
startingLocation[0] += fabCreate.getWidth() / 2;
TakePhotoActivity.startCameraFromLocation(startingLocation, this);
overridePendingTransition(0, 0);
}

public void showLikedSnackbar() {
Snackbar.make(clContent, "Liked!", Snackbar.LENGTH_SHORT).show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ public void onError() {
});
}

@Override
protected boolean shouldInstallDrawer() {
return false;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_publish, menu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ private void setupPhotoFilters() {
rvFilters.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
}

@Override
protected boolean shouldInstallDrawer() {
return false;
}

@Override
protected void onResume() {
super.onResume();
Expand Down
Loading

0 comments on commit d14fba8

Please sign in to comment.