Skip to content

Commit 2f9e84d

Browse files
committed
Issue photo#461 (Card 9) (Remove tags from navigation for collaborators)
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
1 parent c35fa49 commit 2f9e84d

File tree

10 files changed

+172
-40
lines changed

10 files changed

+172
-40
lines changed

app/res/values/settings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<string name="setting_oauth_token_secret">setting_oauth_token_secret</string>
2020
<string name="setting_remaining_upload_limit">setting_remaining_upload_limit</string>
2121
<string name="setting_account_type">setting_account_type</string>
22+
<string name="setting_account_access_type">setting_account_access_type</string>
2223
<string name="setting_upload_limit_reset_date">setting_upload_limit_reset_date</string>
2324
<string name="setting_system_version_info_updated">setting_system_version_info_updated</string>
2425
<string name="setting_system_version_hosted">setting_system_version_hosted</string>

app/src/com/trovebox/android/app/MainActivity.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public void openGallery(String tag, Album album)
350350
}
351351
intent.putExtra(GalleryFragment.EXTRA_TAG, tag);
352352
intent.putExtra(GalleryFragment.EXTRA_ALBUM, album);
353-
selectTab(NavigationHandlerFragment.GALLERY_INDEX);
353+
selectTab(navigationHandlerFragment.getGalleryIndex());
354354
}
355355

356356
@Override
@@ -393,20 +393,21 @@ public void run() {
393393
public void syncStarted()
394394
{
395395
CommonUtils.debug(TAG, "Sync started");
396-
if (navigationHandlerFragment.getSelectedNavigationIndex() == NavigationHandlerFragment.SYNC_INDEX)
396+
if (navigationHandlerFragment.getSelectedNavigationIndex() == navigationHandlerFragment
397+
.getSyncIndex())
397398
{
398399
if (!instanceSaved)
399400
{
400-
selectTab(NavigationHandlerFragment.GALLERY_INDEX);
401+
selectTab(navigationHandlerFragment.getGalleryIndex());
401402
}
402403
}
403404
}
404405

405406
@Override
406407
public void uploadsCleared()
407408
{
408-
SyncFragment fragment = navigationHandlerFragment
409-
.getFragment(NavigationHandlerFragment.SYNC_INDEX);
409+
SyncFragment fragment = navigationHandlerFragment.getFragment(navigationHandlerFragment
410+
.getSyncIndex());
410411
if (fragment != null)
411412
{
412413
fragment.uploadsCleared();
@@ -479,11 +480,12 @@ public void photoUpdated(Photo photo)
479480
@Override
480481
public void startNow() {
481482
CommonUtils.debug(TAG, "Start now");
482-
if (navigationHandlerFragment.getSelectedNavigationIndex() != NavigationHandlerFragment.SYNC_INDEX)
483+
if (navigationHandlerFragment.getSelectedNavigationIndex() != navigationHandlerFragment
484+
.getSyncIndex())
483485
{
484486
if (!instanceSaved)
485487
{
486-
selectTab(NavigationHandlerFragment.SYNC_INDEX);
488+
selectTab(navigationHandlerFragment.getSyncIndex());
487489
}
488490
}
489491
}

app/src/com/trovebox/android/app/NavigationHandlerFragment.java

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,34 @@
4141
*/
4242
public class NavigationHandlerFragment extends CommonFragment {
4343
static final String TAG = NavigationHandlerFragment.class.getSimpleName();
44-
public static final int GALLERY_INDEX = 0;
45-
public static final int ALBUMS_INDEX = GALLERY_INDEX + 1;
46-
public static final int TAGS_INDEX = ALBUMS_INDEX + 1;
47-
public static final int SYNC_INDEX = TAGS_INDEX + 1;
48-
public static final int ACCOUNT_INDEX = SYNC_INDEX + 1;
44+
45+
public int getGalleryIndex() {
46+
return 0;
47+
}
48+
49+
public int getAlbumsIndex() {
50+
return getGalleryIndex() + 1;
51+
}
52+
53+
public int getTagsIndex() {
54+
return hasTags() ? (getAlbumsIndex() + 1) : -1;
55+
}
56+
57+
public int getSyncIndex() {
58+
return (hasTags() ? getTagsIndex() : getAlbumsIndex()) + 1;
59+
}
60+
61+
public int getAccountIndex() {
62+
return getSyncIndex() + 1;
63+
}
64+
65+
/**
66+
* Whether the currently logged in user has access to tags
67+
* @return
68+
*/
69+
boolean hasTags() {
70+
return !Preferences.isLimitedAccountAccessType();
71+
}
4972

5073
public static interface OnMenuClickListener {
5174
public void onMenuClick(int position);
@@ -250,7 +273,7 @@ public void run() {
250273
if (gf != null) {
251274
gf.cleanRefreshIfFiltered();
252275
}
253-
setActionBarTitle(adapter.wrappers.get(GALLERY_INDEX));
276+
setActionBarTitle(adapter.wrappers.get(getGalleryIndex()));
254277
}
255278
});
256279
wrapper.dynamicTitleGenerator = new RunnableWithResult<String>() {
@@ -275,10 +298,12 @@ public String run() {
275298
R.string.tab_albums,
276299
R.drawable.menu_album_2states,
277300
AlbumsFragment.class, null);
278-
adapter.add(
279-
R.string.tab_tags,
280-
R.drawable.menu_tags_2states,
281-
TagsFragment.class, null);
301+
if (hasTags()) {
302+
adapter.add(
303+
R.string.tab_tags,
304+
R.drawable.menu_tags_2states,
305+
TagsFragment.class, null);
306+
}
282307
adapter.add(
283308
R.string.tab_sync,
284309
R.drawable.menu_upload_2states,
@@ -310,9 +335,9 @@ public void run() {
310335
wrapper = adapter.add(R.string.tab_account,
311336
R.drawable.menu_profile_2states,
312337
AccountFragment.class, null, null,
313-
ACCOUNT_INDEX);
338+
getAccountIndex());
314339
wrapper.mSeparatorTitleId = R.string.tab_preferences;
315-
for (int position = ACCOUNT_INDEX + 1, size = adapter
340+
for (int position = getAccountIndex() + 1, size = adapter
316341
.getCount(); position < size; position++)
317342
{
318343
wrapper = adapter.wrappers
@@ -323,7 +348,7 @@ public void run() {
323348
adapter.notifyDataSetChanged();
324349
}
325350
rebuildLeftView();
326-
if (mCurrentPage >= ACCOUNT_INDEX)
351+
if (mCurrentPage >= getAccountIndex())
327352
{
328353
selectTab(mCurrentPage);
329354
}
@@ -335,7 +360,7 @@ public void run() {
335360
// such as account tab may be absent at this step
336361
// we need to exclute tab selection in case actibeTab
337362
// is account
338-
if (mCurrentPage < ACCOUNT_INDEX)
363+
if (mCurrentPage < getAccountIndex())
339364
{
340365
selectTab(mCurrentPage);
341366
}
@@ -389,7 +414,7 @@ public Fragment getCurrentFragment()
389414
*/
390415
public GalleryFragment getGalleryFragment()
391416
{
392-
return getFragment(GALLERY_INDEX);
417+
return getFragment(getGalleryIndex());
393418
}
394419

395420
/**
@@ -399,7 +424,7 @@ public GalleryFragment getGalleryFragment()
399424
*/
400425
public SyncFragment getSyncFragment()
401426
{
402-
return getFragment(SYNC_INDEX);
427+
return getFragment(getSyncIndex());
403428
}
404429

405430
/**
@@ -409,7 +434,7 @@ public SyncFragment getSyncFragment()
409434
*/
410435
public AccountFragment getAccountFragment()
411436
{
412-
Fragment result = getFragment(ACCOUNT_INDEX);
437+
Fragment result = getFragment(getAccountIndex());
413438
if (!(result instanceof AccountFragment))
414439
{
415440
result = null;

app/src/com/trovebox/android/app/Preferences.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import android.content.Context;
1414
import android.content.SharedPreferences;
1515

16+
import com.trovebox.android.app.model.Credentials;
1617
import com.trovebox.android.app.net.ITroveboxApi;
1718
import com.trovebox.android.app.net.TroveboxApi;
1819
import com.trovebox.android.app.purchase.util.Purchase;
@@ -169,6 +170,40 @@ public static void setProUser(boolean value)
169170
.commit();
170171
}
171172

173+
/**
174+
* Set currently loggged in user account access type. Either owner, admin or
175+
* group
176+
*
177+
* @param accessType
178+
*/
179+
public static void setAccountAccessType(String accessType) {
180+
getLimitsSharedPreferences()
181+
.edit()
182+
.putString(CommonUtils.getStringResource(R.string.setting_account_access_type),
183+
accessType).commit();
184+
}
185+
186+
187+
/**
188+
* Get current account access type
189+
*
190+
* @return
191+
*/
192+
public static String getAccountAccessType() {
193+
return getLimitsSharedPreferences().getString(
194+
CommonUtils.getStringResource(R.string.setting_account_access_type),
195+
Credentials.OWNER_TYPE);
196+
}
197+
198+
/**
199+
* Check whether the limited account access is used. Usually that is 'group'
200+
* account access type
201+
*
202+
* @return
203+
*/
204+
public static boolean isLimitedAccountAccessType() {
205+
return getAccountAccessType().equals(Credentials.GROUP_TYPE);
206+
}
172207
/**
173208
* Get the remaining uploading limit
174209
*

app/src/com/trovebox/android/app/model/Credentials.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
* @author Eugene Popovich
1717
*/
1818
public class Credentials implements Parcelable {
19+
public static final String OWNER_TYPE = "owner";
20+
public static final String ADMIN_TYPE = "admin";
21+
public static final String GROUP_TYPE = "group";
22+
1923
private String mHost;
2024
private String mOAuthConsumerKey;
2125
private String mOAuthConsumerSecret;
2226
private String mOAuthToken;
2327
private String mOAuthTokenSecret;
2428
private String mEmail;
29+
private String mType;
2530

2631
private Credentials() {
2732
}
@@ -33,6 +38,7 @@ public Credentials(JSONObject json) throws JSONException {
3338
mOAuthToken = json.getString("userToken");
3439
mOAuthTokenSecret = json.getString("userSecret");
3540
mEmail = json.getString("owner");
41+
mType = json.optString("_type", OWNER_TYPE);
3642
}
3743

3844
public String getHost() {
@@ -63,24 +69,34 @@ public String getEmail() {
6369
return mEmail;
6470
}
6571

72+
public String getType() {
73+
return mType;
74+
}
75+
6676
public void saveCredentials(Context context) {
67-
Preferences.setServer(context, this.getServer());
77+
saveCredentials(context, this);
78+
}
79+
80+
public static void saveCredentials(Context context, Credentials credentials) {
81+
Preferences.setServer(context, credentials.getServer());
6882

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

87+
Preferences.setAccountAccessType(credentials.getType());
88+
7389
Preferences
7490
.getSharedPreferences("oauth")
7591
.edit()
7692
.putString(context.getString(R.string.setting_oauth_consumer_key),
77-
this.getoAuthConsumerKey())
93+
credentials.getoAuthConsumerKey())
7894
.putString(context.getString(R.string.setting_oauth_consumer_secret),
79-
this.getoAuthConsumerSecret())
95+
credentials.getoAuthConsumerSecret())
8096
.putString(context.getString(R.string.setting_oauth_token),
81-
this.getoAuthToken())
97+
credentials.getoAuthToken())
8298
.putString(context.getString(R.string.setting_oauth_token_secret),
83-
this.getoAuthTokenSecret()).commit();
99+
credentials.getoAuthTokenSecret()).commit();
84100
}
85101

86102
/*****************************
@@ -95,6 +111,7 @@ public int describeContents() {
95111
public void writeToParcel(Parcel out, int flags) {
96112
out.writeString(mHost);
97113
out.writeString(mEmail);
114+
out.writeString(mType);
98115
out.writeString(mOAuthConsumerKey);
99116
out.writeString(mOAuthConsumerSecret);
100117
out.writeString(mOAuthToken);
@@ -117,6 +134,7 @@ private Credentials(Parcel in) {
117134
this();
118135
mHost = in.readString();
119136
mEmail = in.readString();
137+
mType = in.readString();
120138
mOAuthConsumerKey = in.readString();
121139
mOAuthConsumerSecret = in.readString();
122140
mOAuthToken = in.readString();

test/res/raw/json_credentials_v2.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{ "_owner" : "[email protected]",
2+
"_type" : "group",
3+
"actor" : "[email protected]",
4+
"clientSecret" : "0f5d654bca",
5+
"dateCreated" : 1381190570,
6+
"host" : "test3.trovebox.com",
7+
"id" : "102230629a6802fbca9825a4617bfe",
8+
"name" : "Jaisen's Phone",
9+
"owner" : "[email protected]",
10+
"profile" : { "counts" : { "albums" : 5,
11+
"photos" : 363,
12+
"tags" : 37
13+
},
14+
"id" : "test3.trovebox.com",
15+
"isOwner" : false,
16+
"name" : " Demo User",
17+
"permission" : { "C" : [ 4 ],
18+
"D" : false,
19+
"R" : [ 4 ],
20+
"U" : false
21+
},
22+
"photoUrl" : "http://awesomeness.openphoto.me/custom/201203/62f010-Boracay-Philippines-033_100x100xCR.jpg"
23+
},
24+
"status" : "1",
25+
"type" : "access",
26+
"userSecret" : "6d1e8fc274",
27+
"userToken" : "b662440d621f2f71352f8865888fe2"
28+
}

test/src/com/trovebox/android/test/GalleryActivityTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.jayway.android.robotium.solo.Solo;
2020
import com.trovebox.android.app.GalleryFragment.GalleryAdapterExt;
2121
import com.trovebox.android.app.MainActivity;
22-
import com.trovebox.android.app.NavigationHandlerFragment;
2322
import com.trovebox.android.app.net.Paging;
2423
import com.trovebox.android.app.net.PhotoResponse;
2524
import com.trovebox.android.app.net.PhotosResponse;
@@ -73,7 +72,7 @@ public void testLoadsImages() throws ClientProtocolException,
7372
@Override
7473
public void run()
7574
{
76-
getActivity().selectTab(NavigationHandlerFragment.GALLERY_INDEX);
75+
getActivity().selectTab(0);
7776
}
7877
});
7978
getInstrumentation().waitForIdleSync();

test/src/com/trovebox/android/test/MainActivityTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.trovebox.android.app.AlbumsFragment;
1313
import com.trovebox.android.app.GalleryFragment;
1414
import com.trovebox.android.app.MainActivity;
15-
import com.trovebox.android.app.NavigationHandlerFragment;
1615
import com.trovebox.android.app.SyncFragment;
1716
import com.trovebox.android.app.TagsFragment;
1817

@@ -50,13 +49,13 @@ public void testPreconditions() throws InterruptedException
5049
public void testTabSelection() throws InterruptedException
5150
{
5251

53-
testSingleTabSelection(NavigationHandlerFragment.GALLERY_INDEX,
52+
testSingleTabSelection(0,
5453
GalleryFragment.class);
55-
testSingleTabSelection(NavigationHandlerFragment.SYNC_INDEX,
54+
testSingleTabSelection(3,
5655
SyncFragment.class);
57-
testSingleTabSelection(NavigationHandlerFragment.ALBUMS_INDEX,
56+
testSingleTabSelection(1,
5857
AlbumsFragment.class);
59-
testSingleTabSelection(NavigationHandlerFragment.TAGS_INDEX,
58+
testSingleTabSelection(2,
6059
TagsFragment.class);
6160

6261
}

0 commit comments

Comments
 (0)