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

Commit

Permalink
enabled fab button for My Profile page, handled rotation for Fab button
Browse files Browse the repository at this point in the history
  • Loading branch information
smukov committed Jun 19, 2016
1 parent 51d5e98 commit a17ef95
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public void onClick(View view) {

//instantiate the fragmentManager and set the default view to profile
currentFragment = new ProfileFragment();
currentFragment.setFloatingActionButton(fab);
fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame ,(Fragment) currentFragment)
Expand Down Expand Up @@ -112,7 +111,6 @@ public boolean onNavigationItemSelected(MenuItem item) {
currentFragment = new ProfileFragment();
}

currentFragment.setFloatingActionButton(fab);
fragmentManager.beginTransaction()
.replace(R.id.content_frame, (Fragment) currentFragment)
.commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,5 @@ public abstract class BaseNavigationFragment extends Fragment
protected View myView;
protected FloatingActionButton fab;

@Override
public void setFloatingActionButton(FloatingActionButton fab) {
this.fab = fab;
}

protected abstract void prepareFloatingActionButton();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -37,6 +38,10 @@ public void onViewCreated(View view, Bundle savedInstanceState) {

@Override
protected void prepareFloatingActionButton(){
if(fab == null){
fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
}

fab.show();
fab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_forum_black_24dp));
fab.setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.thesis.smukov.anative.NavigationFragment;

import android.support.design.widget.FloatingActionButton;

/**
* Created by smuko on 18-Jun-16.
*/
public interface INavigationFragment {
void setFloatingActionButton(FloatingActionButton fab);

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.thesis.smukov.anative.NavigationFragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.thesis.smukov.anative.R;
Expand All @@ -16,7 +18,14 @@
*/
public class ProfileFragment extends BaseNavigationFragment {

Boolean isEditable = false;

TextView profileName;
EditText txtEmployment;
EditText txtEducation;
EditText txtInterests;
EditText txtKnowledgeable;
EditText txtCurrentGoals;

@Nullable
@Override
Expand All @@ -25,6 +34,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
return myView;
}

@SuppressLint("WrongViewCast")
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Expand All @@ -33,18 +43,44 @@ public void onViewCreated(View view, Bundle savedInstanceState) {

profileName = (TextView) view.findViewById(R.id.profile_name);
profileName.setText("Dr. Gregory House");

txtEmployment = (EditText) view.findViewById(R.id.txtEmployment);
txtEducation = (EditText) view.findViewById(R.id.txtEducation);
txtInterests = (EditText) view.findViewById(R.id.txtInterests);
txtKnowledgeable = (EditText) view.findViewById(R.id.txtKnowledgeable);
txtCurrentGoals = (EditText) view.findViewById(R.id.txtCurrentGoals);

toggleEditMode(isEditable);
}

@Override
protected void prepareFloatingActionButton(){
if(fab == null){
fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
}

fab.show();
fab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_create_black_24dp));
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Called from Profile Fragment", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
isEditable = !isEditable;
toggleEditMode(isEditable);
}
});
}

private void toggleEditMode(Boolean isEditable){
txtEmployment.setEnabled(isEditable);
txtEducation.setEnabled(isEditable);
txtInterests.setEnabled(isEditable);
txtKnowledgeable.setEnabled(isEditable);
txtCurrentGoals.setEnabled(isEditable);

if(isEditable){
fab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_done_black_24dp));
}else{
fab.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_create_black_24dp));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -29,6 +30,9 @@ public void onViewCreated(View view, Bundle savedInstanceState) {

@Override
protected void prepareFloatingActionButton(){
if(fab == null){
fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
}
fab.hide();
}
}
6 changes: 3 additions & 3 deletions Android/app/src/main/res/layout/profile_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@id/txtInterests"
android:id="@+id/txtInterests"
android:layout_gravity="center_horizontal"
android:hint="@string/hint_interests" />

Expand All @@ -63,7 +63,7 @@
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@id/txtKnowledgeable"
android:id="@+id/txtKnowledgeable"
android:layout_gravity="center_horizontal"
android:hint="@string/hint_knowledgeable" />

Expand All @@ -85,7 +85,7 @@
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="@id/txtCurrentGoals"
android:id="@+id/txtCurrentGoals"
android:layout_gravity="center_horizontal"
android:hint="@string/hint_goals" />

Expand Down

0 comments on commit a17ef95

Please sign in to comment.