Skip to content
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

Profile View and UI fixes #79

Merged
merged 6 commits into from
Feb 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
<activity
android:name=".activities.PostActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_post" >
android:label="@string/title_activity_post"
android:theme="@style/Theme.Yellr">
</activity>
<activity
android:name=".activities.ViewStoryActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import yellr.net.yellr_android.fragments.AssignmentsFragment;
import yellr.net.yellr_android.fragments.PostFragment;
import yellr.net.yellr_android.fragments.StoriesFragment;
import yellr.net.yellr_android.utils.YellrUtils;

public class HomeActivity extends ActionBarActivity implements ActionBar.TabListener, AssignmentsFragment.OnFragmentInteractionListener, StoriesFragment.OnFragmentInteractionListener {

Expand Down Expand Up @@ -54,27 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
// See if we have a clientId in shared preferences, and if we
// don't then create one
//

String clientId = "";

// read the clientId from the device.
SharedPreferences sharedPref = this.getSharedPreferences("clientId", Context.MODE_PRIVATE);
clientId = sharedPref.getString("clientId", "");

// check to see if there is a clientId on the device, if not created one
if (clientId.equals("")){

clientId = UUID.randomUUID().toString();
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("clientId", clientId);
editor.commit();

}


//
// fire all of the intent services so we can stay up-to-date
//
String clientId = YellrUtils.getUUID(this);

//IntentServicesHelper.getAssignments(this,clientId);
//IntentServicesHelper.getStories(this,clientId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package yellr.net.yellr_android.activities;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import yellr.net.yellr_android.R;
import yellr.net.yellr_android.fragments.PostFragment;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,65 +1,21 @@
package yellr.net.yellr_android.activities;

import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import yellr.net.yellr_android.R;
import yellr.net.yellr_android.fragments.ProfileFragment;

public class ProfileActivity extends ActionBarActivity {
public class ProfileActivity extends ActionBarActivity{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.add(R.id.container, new ProfileFragment().newInstance())
.commit();
}
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_profile, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_profile, container, false);
return rootView;
}
}
}
165 changes: 106 additions & 59 deletions app/src/main/java/yellr/net/yellr_android/fragments/ProfileFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,60 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.Uri;
import android.graphics.Typeface;
import android.os.Bundle;
import android.app.Fragment;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.google.gson.Gson;
import com.joanzapata.android.iconify.IconDrawable;
import com.joanzapata.android.iconify.Iconify;


import yellr.net.yellr_android.R;
import yellr.net.yellr_android.intent_services.profile.ProfileIntentService;
import yellr.net.yellr_android.intent_services.profile.ProfileResponse;
import yellr.net.yellr_android.utils.YellrUtils;

/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link ProfileFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link ProfileFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class ProfileFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
public static final String DIALOG_RESET_UUID = "yellr.net.yellr_android.dialog.RESET_UUID";

private String clientId;

private OnFragmentInteractionListener mListener;
private TextView userImage;
private TextView userName;
TextView userUUID;
private TextView userVerifiedIcon;
private TextView userVerified;
TextView postsIcon;
private TextView postsNumber;
TextView postsViewedIcon;
private TextView postsViewedNumber;
TextView postsUsedIcon;
private TextView postsUsedNumber;

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ProfileFragment.
*/
// TODO: Rename and change types and number of parameters
public static ProfileFragment newInstance(String param1, String param2) {
public static ProfileFragment newInstance() {
ProfileFragment fragment = new ProfileFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
Expand Down Expand Up @@ -84,12 +88,13 @@ private void refreshProfileData() {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);

}

Log.d("ProfileFragment.onCreate()","Setting up IntentService receiver ...");

setHasOptionsMenu(true);

// get clientId
SharedPreferences sharedPref = getActivity().getSharedPreferences("clientId", Context.MODE_PRIVATE);
clientId = sharedPref.getString("clientId", "");
Expand All @@ -107,46 +112,83 @@ public void onCreate(Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_profile, container, false);
}
View view = inflater.inflate(R.layout.fragment_profile, container, false);
Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fontawesome-webfont.ttf");

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
userImage = (TextView) view.findViewById(R.id.frag_profile_user_image);
userImage.setTypeface(font);
userImage.setText(R.string.fa_user_secret);

userName = (TextView) view.findViewById(R.id.frag_profile_name);
userUUID = (TextView) view.findViewById(R.id.frag_profile_id);
userUUID.setText(String.format("UUID: %s", clientId));

userVerified = (TextView) view.findViewById(R.id.frag_profile_verified);
userVerifiedIcon = (TextView)view.findViewById(R.id.frag_profile_verified_icon);
userVerifiedIcon.setTypeface(font);

postsIcon = (TextView)view.findViewById(R.id.frag_profile_posts_icon);
postsIcon.setTypeface(font);
postsNumber = (TextView)view.findViewById(R.id.frag_profile_posts_number);

postsViewedIcon = (TextView)view.findViewById(R.id.frag_profile_viewed_posts_icon);
postsViewedIcon.setTypeface(font);
postsViewedNumber = (TextView)view.findViewById(R.id.frag_profile_viewed_posts_number);

postsUsedIcon = (TextView)view.findViewById(R.id.frag_profile_used_posts_icon);
postsUsedIcon.setTypeface(font);
postsUsedNumber = (TextView)view.findViewById(R.id.frag_profile_used_posts_number);

return view;
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnFragmentInteractionListener");
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_profile, menu);
if(this.isAdded()){
menu.findItem(R.id.action_profile_signup).setIcon(
new IconDrawable(getActivity(), Iconify.IconValue.fa_user_plus)
.colorRes(R.color.black)
.actionBarSize()
);
menu.findItem(R.id.action_profile_new_uuid).setIcon(
new IconDrawable(getActivity(), Iconify.IconValue.fa_key)
.colorRes(R.color.black)
.actionBarSize()
);
} else {
Log.d("onCreateOptionsMenu()", "Fragment not added to Activity");
}
super.onCreateOptionsMenu(menu, inflater);
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.action_profile_new_uuid:
ResetUUIDFragment resetUUIDFragment = new ResetUUIDFragment();
resetUUIDFragment.setTargetFragment(this, 1);
resetUUIDFragment.show(getFragmentManager(), DIALOG_RESET_UUID);
break;
case R.id.action_profile_signup:

break;
default:
break;
}
return super.onOptionsItemSelected(item);
}

/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p/>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
public void onFragmentInteraction(Uri uri);
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (resultCode == Activity.RESULT_OK){
userUUID.setText(String.format("UUID: %s", YellrUtils.getUUID(getActivity())));
postsNumber.setText("0");
postsViewedNumber.setText("0");
postsUsedNumber.setText("0");
}
}

public class ProfileReceiver extends BroadcastReceiver {
Expand All @@ -158,20 +200,25 @@ public ProfileReceiver() {

@Override
public void onReceive(Context context, Intent intent) {

//Log.d("ProfileReceiver.onReceive()", "onReceive called.");

String profileJson = intent.getStringExtra(ProfileIntentService.PARAM_PROFILE_JSON);

//Log.d("ProfileReceiver.onReceive()", "JSON: " + profileJson);

Gson gson = new Gson();
ProfileResponse response = gson.fromJson(profileJson, ProfileResponse.class);

if ( response.success ) {

// TODO: populate GUI with array of Profile

if(!response.first_name.isEmpty()){
userName.setText(response.first_name + " " + response.last_name);
userImage.setText(R.string.fa_user);

}

if(response.verified){
userVerified.setText("Verified");
userVerifiedIcon.setText(R.string.fa_check_square);
}
postsNumber.setText(String.valueOf(response.post_count));
postsViewedNumber.setText(String.valueOf(response.post_view_count));
postsUsedNumber.setText(String.valueOf(response.post_used_count));
/*
{
"first_name": "",
Expand Down
Loading