Skip to content

Commit

Permalink
Issue photo#461 (Card 9) (Remove tags from navigation for collaborators)
Browse files Browse the repository at this point in the history
app:
- MainActivity: replaced NavigationFragment index constant acccess with
the proper get methods from nafigationFragment field everywhere
- NavigationHandlerFragment: removed index constants such as they are
not constants anymore
- NiavigationHandlerFragment: added new methods getGalleryIndex,
getAlbumsIndex, getTagsIndex, getSyncIndex, getAccountIndex, hasTags
- NavigationHandlerFragment: replaced index constant access with
corresponding methods everywhere
- NavigationHandlerFragment: added hasTags check to the initPager method
before adding tags to the navigation
- Preferences added new methods setAccountAccessType,
getAccountAccessType, isLimitedAccountAccessType
- Credentials: added new access type constants
- Credentials: added mType field and it support to Parcelable
implementation and constructor
- Credentials: added getType getter
- Credentials: added static method saveCredentials and saving of account
access type to preferences cache there
- res/values/settings.xml: added setting_account_access_type constant
test:
- GalleryActivityTest, MainActivityTest: fixed compilation issues caused
by NavigationHandlerFragment updates
- CredentialsTest: added new test case testCredentialsParcelableV2
- CredentialsTest: updated checkCredentialsV2 signature (added type
support)
- AccountTroveboxResponseTest: updated calls of
CredentialsTest.checkCredentialsV2 with proper types in the
testMultiResponseV2 method
- res/raw/json_credentials_v2.txt: added
  • Loading branch information
httpdispatch committed Oct 10, 2013
1 parent c35fa49 commit 2f9e84d
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 40 deletions.
1 change: 1 addition & 0 deletions app/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<string name="setting_oauth_token_secret">setting_oauth_token_secret</string>
<string name="setting_remaining_upload_limit">setting_remaining_upload_limit</string>
<string name="setting_account_type">setting_account_type</string>
<string name="setting_account_access_type">setting_account_access_type</string>
<string name="setting_upload_limit_reset_date">setting_upload_limit_reset_date</string>
<string name="setting_system_version_info_updated">setting_system_version_info_updated</string>
<string name="setting_system_version_hosted">setting_system_version_hosted</string>
Expand Down
16 changes: 9 additions & 7 deletions app/src/com/trovebox/android/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public void openGallery(String tag, Album album)
}
intent.putExtra(GalleryFragment.EXTRA_TAG, tag);
intent.putExtra(GalleryFragment.EXTRA_ALBUM, album);
selectTab(NavigationHandlerFragment.GALLERY_INDEX);
selectTab(navigationHandlerFragment.getGalleryIndex());
}

@Override
Expand Down Expand Up @@ -393,20 +393,21 @@ public void run() {
public void syncStarted()
{
CommonUtils.debug(TAG, "Sync started");
if (navigationHandlerFragment.getSelectedNavigationIndex() == NavigationHandlerFragment.SYNC_INDEX)
if (navigationHandlerFragment.getSelectedNavigationIndex() == navigationHandlerFragment
.getSyncIndex())
{
if (!instanceSaved)
{
selectTab(NavigationHandlerFragment.GALLERY_INDEX);
selectTab(navigationHandlerFragment.getGalleryIndex());
}
}
}

@Override
public void uploadsCleared()
{
SyncFragment fragment = navigationHandlerFragment
.getFragment(NavigationHandlerFragment.SYNC_INDEX);
SyncFragment fragment = navigationHandlerFragment.getFragment(navigationHandlerFragment
.getSyncIndex());
if (fragment != null)
{
fragment.uploadsCleared();
Expand Down Expand Up @@ -479,11 +480,12 @@ public void photoUpdated(Photo photo)
@Override
public void startNow() {
CommonUtils.debug(TAG, "Start now");
if (navigationHandlerFragment.getSelectedNavigationIndex() != NavigationHandlerFragment.SYNC_INDEX)
if (navigationHandlerFragment.getSelectedNavigationIndex() != navigationHandlerFragment
.getSyncIndex())
{
if (!instanceSaved)
{
selectTab(NavigationHandlerFragment.SYNC_INDEX);
selectTab(navigationHandlerFragment.getSyncIndex());
}
}
}
Expand Down
59 changes: 42 additions & 17 deletions app/src/com/trovebox/android/app/NavigationHandlerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,34 @@
*/
public class NavigationHandlerFragment extends CommonFragment {
static final String TAG = NavigationHandlerFragment.class.getSimpleName();
public static final int GALLERY_INDEX = 0;
public static final int ALBUMS_INDEX = GALLERY_INDEX + 1;
public static final int TAGS_INDEX = ALBUMS_INDEX + 1;
public static final int SYNC_INDEX = TAGS_INDEX + 1;
public static final int ACCOUNT_INDEX = SYNC_INDEX + 1;

public int getGalleryIndex() {
return 0;
}

public int getAlbumsIndex() {
return getGalleryIndex() + 1;
}

public int getTagsIndex() {
return hasTags() ? (getAlbumsIndex() + 1) : -1;
}

public int getSyncIndex() {
return (hasTags() ? getTagsIndex() : getAlbumsIndex()) + 1;
}

public int getAccountIndex() {
return getSyncIndex() + 1;
}

/**
* Whether the currently logged in user has access to tags
* @return
*/
boolean hasTags() {
return !Preferences.isLimitedAccountAccessType();
}

public static interface OnMenuClickListener {
public void onMenuClick(int position);
Expand Down Expand Up @@ -250,7 +273,7 @@ public void run() {
if (gf != null) {
gf.cleanRefreshIfFiltered();
}
setActionBarTitle(adapter.wrappers.get(GALLERY_INDEX));
setActionBarTitle(adapter.wrappers.get(getGalleryIndex()));
}
});
wrapper.dynamicTitleGenerator = new RunnableWithResult<String>() {
Expand All @@ -275,10 +298,12 @@ public String run() {
R.string.tab_albums,
R.drawable.menu_album_2states,
AlbumsFragment.class, null);
adapter.add(
R.string.tab_tags,
R.drawable.menu_tags_2states,
TagsFragment.class, null);
if (hasTags()) {
adapter.add(
R.string.tab_tags,
R.drawable.menu_tags_2states,
TagsFragment.class, null);
}
adapter.add(
R.string.tab_sync,
R.drawable.menu_upload_2states,
Expand Down Expand Up @@ -310,9 +335,9 @@ public void run() {
wrapper = adapter.add(R.string.tab_account,
R.drawable.menu_profile_2states,
AccountFragment.class, null, null,
ACCOUNT_INDEX);
getAccountIndex());
wrapper.mSeparatorTitleId = R.string.tab_preferences;
for (int position = ACCOUNT_INDEX + 1, size = adapter
for (int position = getAccountIndex() + 1, size = adapter
.getCount(); position < size; position++)
{
wrapper = adapter.wrappers
Expand All @@ -323,7 +348,7 @@ public void run() {
adapter.notifyDataSetChanged();
}
rebuildLeftView();
if (mCurrentPage >= ACCOUNT_INDEX)
if (mCurrentPage >= getAccountIndex())
{
selectTab(mCurrentPage);
}
Expand All @@ -335,7 +360,7 @@ public void run() {
// such as account tab may be absent at this step
// we need to exclute tab selection in case actibeTab
// is account
if (mCurrentPage < ACCOUNT_INDEX)
if (mCurrentPage < getAccountIndex())
{
selectTab(mCurrentPage);
}
Expand Down Expand Up @@ -389,7 +414,7 @@ public Fragment getCurrentFragment()
*/
public GalleryFragment getGalleryFragment()
{
return getFragment(GALLERY_INDEX);
return getFragment(getGalleryIndex());
}

/**
Expand All @@ -399,7 +424,7 @@ public GalleryFragment getGalleryFragment()
*/
public SyncFragment getSyncFragment()
{
return getFragment(SYNC_INDEX);
return getFragment(getSyncIndex());
}

/**
Expand All @@ -409,7 +434,7 @@ public SyncFragment getSyncFragment()
*/
public AccountFragment getAccountFragment()
{
Fragment result = getFragment(ACCOUNT_INDEX);
Fragment result = getFragment(getAccountIndex());
if (!(result instanceof AccountFragment))
{
result = null;
Expand Down
35 changes: 35 additions & 0 deletions app/src/com/trovebox/android/app/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.content.Context;
import android.content.SharedPreferences;

import com.trovebox.android.app.model.Credentials;
import com.trovebox.android.app.net.ITroveboxApi;
import com.trovebox.android.app.net.TroveboxApi;
import com.trovebox.android.app.purchase.util.Purchase;
Expand Down Expand Up @@ -169,6 +170,40 @@ public static void setProUser(boolean value)
.commit();
}

/**
* Set currently loggged in user account access type. Either owner, admin or
* group
*
* @param accessType
*/
public static void setAccountAccessType(String accessType) {
getLimitsSharedPreferences()
.edit()
.putString(CommonUtils.getStringResource(R.string.setting_account_access_type),
accessType).commit();
}


/**
* Get current account access type
*
* @return
*/
public static String getAccountAccessType() {
return getLimitsSharedPreferences().getString(
CommonUtils.getStringResource(R.string.setting_account_access_type),
Credentials.OWNER_TYPE);
}

/**
* Check whether the limited account access is used. Usually that is 'group'
* account access type
*
* @return
*/
public static boolean isLimitedAccountAccessType() {
return getAccountAccessType().equals(Credentials.GROUP_TYPE);
}
/**
* Get the remaining uploading limit
*
Expand Down
28 changes: 23 additions & 5 deletions app/src/com/trovebox/android/app/model/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
* @author Eugene Popovich
*/
public class Credentials implements Parcelable {
public static final String OWNER_TYPE = "owner";
public static final String ADMIN_TYPE = "admin";
public static final String GROUP_TYPE = "group";

private String mHost;
private String mOAuthConsumerKey;
private String mOAuthConsumerSecret;
private String mOAuthToken;
private String mOAuthTokenSecret;
private String mEmail;
private String mType;

private Credentials() {
}
Expand All @@ -33,6 +38,7 @@ public Credentials(JSONObject json) throws JSONException {
mOAuthToken = json.getString("userToken");
mOAuthTokenSecret = json.getString("userSecret");
mEmail = json.getString("owner");
mType = json.optString("_type", OWNER_TYPE);
}

public String getHost() {
Expand Down Expand Up @@ -63,24 +69,34 @@ public String getEmail() {
return mEmail;
}

public String getType() {
return mType;
}

public void saveCredentials(Context context) {
Preferences.setServer(context, this.getServer());
saveCredentials(context, this);
}

public static void saveCredentials(Context context, Credentials credentials) {
Preferences.setServer(context, credentials.getServer());

Preferences.getDefaultSharedPreferences(context).edit()
.putBoolean(context.getString(R.string.setting_account_loggedin_key), true)
.commit();

Preferences.setAccountAccessType(credentials.getType());

Preferences
.getSharedPreferences("oauth")
.edit()
.putString(context.getString(R.string.setting_oauth_consumer_key),
this.getoAuthConsumerKey())
credentials.getoAuthConsumerKey())
.putString(context.getString(R.string.setting_oauth_consumer_secret),
this.getoAuthConsumerSecret())
credentials.getoAuthConsumerSecret())
.putString(context.getString(R.string.setting_oauth_token),
this.getoAuthToken())
credentials.getoAuthToken())
.putString(context.getString(R.string.setting_oauth_token_secret),
this.getoAuthTokenSecret()).commit();
credentials.getoAuthTokenSecret()).commit();
}

/*****************************
Expand All @@ -95,6 +111,7 @@ public int describeContents() {
public void writeToParcel(Parcel out, int flags) {
out.writeString(mHost);
out.writeString(mEmail);
out.writeString(mType);
out.writeString(mOAuthConsumerKey);
out.writeString(mOAuthConsumerSecret);
out.writeString(mOAuthToken);
Expand All @@ -117,6 +134,7 @@ private Credentials(Parcel in) {
this();
mHost = in.readString();
mEmail = in.readString();
mType = in.readString();
mOAuthConsumerKey = in.readString();
mOAuthConsumerSecret = in.readString();
mOAuthToken = in.readString();
Expand Down
28 changes: 28 additions & 0 deletions test/res/raw/json_credentials_v2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ "_owner" : "hellox2@trovebox.com",
"_type" : "group",
"actor" : "hello@trovebox.com",
"clientSecret" : "0f5d654bca",
"dateCreated" : 1381190570,
"host" : "test3.trovebox.com",
"id" : "102230629a6802fbca9825a4617bfe",
"name" : "Jaisen's Phone",
"owner" : "hellox2@trovebox.com",
"profile" : { "counts" : { "albums" : 5,
"photos" : 363,
"tags" : 37
},
"id" : "test3.trovebox.com",
"isOwner" : false,
"name" : " Demo User",
"permission" : { "C" : [ 4 ],
"D" : false,
"R" : [ 4 ],
"U" : false
},
"photoUrl" : "http://awesomeness.openphoto.me/custom/201203/62f010-Boracay-Philippines-033_100x100xCR.jpg"
},
"status" : "1",
"type" : "access",
"userSecret" : "6d1e8fc274",
"userToken" : "b662440d621f2f71352f8865888fe2"
}
3 changes: 1 addition & 2 deletions test/src/com/trovebox/android/test/GalleryActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.jayway.android.robotium.solo.Solo;
import com.trovebox.android.app.GalleryFragment.GalleryAdapterExt;
import com.trovebox.android.app.MainActivity;
import com.trovebox.android.app.NavigationHandlerFragment;
import com.trovebox.android.app.net.Paging;
import com.trovebox.android.app.net.PhotoResponse;
import com.trovebox.android.app.net.PhotosResponse;
Expand Down Expand Up @@ -73,7 +72,7 @@ public void testLoadsImages() throws ClientProtocolException,
@Override
public void run()
{
getActivity().selectTab(NavigationHandlerFragment.GALLERY_INDEX);
getActivity().selectTab(0);
}
});
getInstrumentation().waitForIdleSync();
Expand Down
9 changes: 4 additions & 5 deletions test/src/com/trovebox/android/test/MainActivityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.trovebox.android.app.AlbumsFragment;
import com.trovebox.android.app.GalleryFragment;
import com.trovebox.android.app.MainActivity;
import com.trovebox.android.app.NavigationHandlerFragment;
import com.trovebox.android.app.SyncFragment;
import com.trovebox.android.app.TagsFragment;

Expand Down Expand Up @@ -50,13 +49,13 @@ public void testPreconditions() throws InterruptedException
public void testTabSelection() throws InterruptedException
{

testSingleTabSelection(NavigationHandlerFragment.GALLERY_INDEX,
testSingleTabSelection(0,
GalleryFragment.class);
testSingleTabSelection(NavigationHandlerFragment.SYNC_INDEX,
testSingleTabSelection(3,
SyncFragment.class);
testSingleTabSelection(NavigationHandlerFragment.ALBUMS_INDEX,
testSingleTabSelection(1,
AlbumsFragment.class);
testSingleTabSelection(NavigationHandlerFragment.TAGS_INDEX,
testSingleTabSelection(2,
TagsFragment.class);

}
Expand Down
Loading

0 comments on commit 2f9e84d

Please sign in to comment.