@@ -150,6 +150,7 @@ public class PhotoDetailsActivity extends BaseActivity implements View.OnClickLi |
||
150 | 150 |
initViews(); |
151 | 151 |
photoPageAdapter = new DetailPhotoPageAdapter(this,photoList); |
152 | 152 |
photoPager.setAdapter(photoPageAdapter); |
153 |
+ photoPageAdapter.setFromGroup(fromGroupPage); |
|
153 | 154 |
photoPager.addOnPageChangeListener(this); |
154 | 155 |
photoPager.setCurrentItem(photoList.indexOf(currentPhotoItem)); |
155 | 156 |
updateDetailHead(); |
@@ -17,18 +17,26 @@ import com.android.common.utils.LogHelper; |
||
17 | 17 |
import com.android.views.progressbar.ProgressWheel; |
18 | 18 |
import com.umeng.analytics.MobclickAgent; |
19 | 19 |
|
20 |
+import org.json.JSONArray; |
|
21 |
+import org.json.JSONObject; |
|
22 |
+ |
|
20 | 23 |
import java.io.File; |
21 | 24 |
import java.io.FileOutputStream; |
22 | 25 |
import java.io.InputStream; |
23 | 26 |
import java.net.HttpURLConnection; |
24 | 27 |
import java.net.URL; |
25 | 28 |
import java.util.ArrayList; |
29 |
+import java.util.HashMap; |
|
26 | 30 |
|
27 | 31 |
import ai.pai.client.BuildConfig; |
28 | 32 |
import ai.pai.client.R; |
29 | 33 |
import ai.pai.client.adapter.FullScreenPhotoPageAdapter; |
30 | 34 |
import ai.pai.client.beans.GroupPhotoItem; |
35 |
+import ai.pai.client.db.DBService; |
|
36 |
+import ai.pai.client.db.Preferences; |
|
37 |
+import ai.pai.client.utils.HttpPostTask; |
|
31 | 38 |
import ai.pai.client.utils.UmengEvent; |
39 |
+import ai.pai.client.utils.UrlContainer; |
|
32 | 40 |
import ai.pai.client.views.HackyViewPager; |
33 | 41 |
|
34 | 42 |
public class PhotoFullScreenActivity extends BaseActivity implements View.OnClickListener, ViewPager.OnPageChangeListener { |
@@ -38,6 +46,10 @@ public class PhotoFullScreenActivity extends BaseActivity implements View.OnClic |
||
38 | 46 |
private GroupPhotoItem currentPhotoItem; |
39 | 47 |
private ProgressWheel spinner; |
40 | 48 |
private SavePhotoTask savePhotoTask; |
49 |
+ private FullScreenPhotoPageAdapter photoPageAdapter; |
|
50 |
+ private HttpPostTask fetchPhotosTask; |
|
51 |
+ private int currentGroupPhotoId; |
|
52 |
+ private boolean fromGroupPage; |
|
41 | 53 |
|
42 | 54 |
@Override |
43 | 55 |
protected void onCreate(Bundle savedInstanceState) { |
@@ -46,9 +58,16 @@ public class PhotoFullScreenActivity extends BaseActivity implements View.OnClic |
||
46 | 58 |
|
47 | 59 |
photoList = (ArrayList<GroupPhotoItem>) getIntent().getSerializableExtra("list"); |
48 | 60 |
currentPhotoItem = (GroupPhotoItem) getIntent().getSerializableExtra("photo_item"); |
61 |
+ fromGroupPage = getIntent().getBooleanExtra("fromGroup",false); |
|
62 |
+ if(fromGroupPage){ |
|
63 |
+ currentGroupPhotoId= DBService.getInstance(this).getCurrentIdByGroupId(currentPhotoItem.groupId); |
|
64 |
+ } |
|
65 |
+ if(photoList.size()>=300){ |
|
66 |
+ currentGroupPhotoId = 0; |
|
67 |
+ } |
|
49 | 68 |
HackyViewPager photoPager = (HackyViewPager) findViewById(R.id.pager_photo); |
50 | 69 |
spinner = (ProgressWheel)findViewById(R.id.wheel_wait_http); |
51 |
- FullScreenPhotoPageAdapter photoPageAdapter = new FullScreenPhotoPageAdapter(this, photoList,photoPager); |
|
70 |
+ photoPageAdapter = new FullScreenPhotoPageAdapter(this, photoList,photoPager); |
|
52 | 71 |
photoPager.setAdapter(photoPageAdapter); |
53 | 72 |
photoPager.addOnPageChangeListener(this); |
54 | 73 |
photoPager.setCurrentItem(photoList.indexOf(currentPhotoItem)); |
@@ -90,12 +109,22 @@ public class PhotoFullScreenActivity extends BaseActivity implements View.OnClic |
||
90 | 109 |
|
91 | 110 |
@Override |
92 | 111 |
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { |
93 |
- |
|
112 |
+ if(position==photoList.size()-1){ |
|
113 |
+ if(fetchPhotosTask!=null && fetchPhotosTask.getStatus()== AsyncTask.Status.RUNNING){ |
|
114 |
+ Toast.makeText(this,R.string.please_wait,Toast.LENGTH_SHORT).show(); |
|
115 |
+ } |
|
116 |
+ } |
|
94 | 117 |
} |
95 | 118 |
|
96 | 119 |
@Override |
97 | 120 |
public void onPageSelected(int position) { |
98 | 121 |
currentPhotoItem = photoList.get(position); |
122 |
+ if(position>=photoList.size()-1){ |
|
123 |
+ Bundle bundle = new Bundle(); |
|
124 |
+ bundle.putString("group_id",currentPhotoItem.groupId); |
|
125 |
+ bundle.putString("current_id",String.valueOf(currentGroupPhotoId)); |
|
126 |
+ loadMoreGroupPhotos(bundle); |
|
127 |
+ } |
|
99 | 128 |
} |
100 | 129 |
|
101 | 130 |
@Override |
@@ -103,6 +132,86 @@ public class PhotoFullScreenActivity extends BaseActivity implements View.OnClic |
||
103 | 132 |
|
104 | 133 |
} |
105 | 134 |
|
135 |
+ private synchronized void loadMoreGroupPhotos(final Bundle bundle){ |
|
136 |
+ if(fetchPhotosTask!=null && fetchPhotosTask.getStatus()== AsyncTask.Status.RUNNING){ |
|
137 |
+ return; |
|
138 |
+ } |
|
139 |
+ HashMap<String,String> params = new HashMap<>(); |
|
140 |
+ params.put("group_id",bundle.getString("group_id")); |
|
141 |
+ params.put("user_id", Preferences.getInstance(this).getUserId()); |
|
142 |
+ params.put("current_id",bundle.getString("current_id")); |
|
143 |
+ LogHelper.d(TAG,"loadMoreGroupPhotos with local currentId = "+bundle.getString("current_id")); |
|
144 |
+ |
|
145 |
+ fetchPhotosTask = new HttpPostTask(this,params) { |
|
146 |
+ ArrayList<GroupPhotoItem> photoItems; |
|
147 |
+ String groupId = bundle.getString("group_id"); |
|
148 |
+ @Override |
|
149 |
+ protected boolean parseResponse(Context context, String response) { |
|
150 |
+ try{ |
|
151 |
+ JSONObject json = new JSONObject(response); |
|
152 |
+ int status = json.getInt("status"); |
|
153 |
+ if(status == 200){ |
|
154 |
+ LogHelper.d(TAG,"group service loadMoreGroupPhotos parseResponse status 200"); |
|
155 |
+ JSONObject info = json.getJSONObject("data"); |
|
156 |
+ if(currentGroupPhotoId==info.getInt("current_id")){ |
|
157 |
+ return false; |
|
158 |
+ } |
|
159 |
+ JSONArray sessionArray = info.getJSONArray("photos"); |
|
160 |
+ if(sessionArray!=null && sessionArray.length()>0) { |
|
161 |
+ photoItems = new ArrayList<>(); |
|
162 |
+ for(int k = 0; k<sessionArray.length();k++){ |
|
163 |
+ JSONObject sessionObj = sessionArray.getJSONObject(k); |
|
164 |
+ String sessionId = sessionObj.getString("session_id"); |
|
165 |
+ JSONArray photoArray = sessionObj.getJSONArray("photos"); |
|
166 |
+ if(photoArray!=null && photoArray.length()>0){ |
|
167 |
+ for(int m = 0; m<photoArray.length();m++){ |
|
168 |
+ JSONObject photoObj = photoArray.getJSONObject(m); |
|
169 |
+ GroupPhotoItem groupPhotoItem = GroupPhotoItem.parseFromJSON(photoObj); |
|
170 |
+ groupPhotoItem.sessionId = sessionId; |
|
171 |
+ photoItems.add(groupPhotoItem); |
|
172 |
+ } |
|
173 |
+ } |
|
174 |
+ } |
|
175 |
+ LogHelper.d(TAG,"group service loadMoreGroupPhotos get new photos ,count="+photoItems.size()); |
|
176 |
+ } |
|
177 |
+ |
|
178 |
+ currentGroupPhotoId = info.getInt("current_id"); |
|
179 |
+ LogHelper.d(TAG,"loadMoreGroupPhotos with server currentId = "+currentGroupPhotoId+"groupId="+groupId); |
|
180 |
+ return true; |
|
181 |
+ } |
|
182 |
+ }catch (Exception e){ |
|
183 |
+ LogHelper.e(TAG,"group service loadMoreGroupPhotos error happen "+e); |
|
184 |
+ } |
|
185 |
+ return false; |
|
186 |
+ } |
|
187 |
+ |
|
188 |
+ @Override |
|
189 |
+ protected void onPostFail(Context context) { |
|
190 |
+ super.onPostFail(context); |
|
191 |
+ |
|
192 |
+ } |
|
193 |
+ |
|
194 |
+ @Override |
|
195 |
+ protected void onPostSuccess(Context context) { |
|
196 |
+ super.onPostSuccess(context); |
|
197 |
+ |
|
198 |
+ if(photoItems!=null && photoItems.size()>0){ |
|
199 |
+ ArrayList<GroupPhotoItem> newPhotos = new ArrayList<>(); |
|
200 |
+ for(GroupPhotoItem photoItem : photoItems){ |
|
201 |
+ if(!photoList.contains(photoItem)){ |
|
202 |
+ newPhotos.add(photoItem); |
|
203 |
+ } |
|
204 |
+ } |
|
205 |
+ if(newPhotos.size()==0){ |
|
206 |
+ return; |
|
207 |
+ } |
|
208 |
+ photoList.addAll(newPhotos); |
|
209 |
+ photoPageAdapter.addPhotos(newPhotos); |
|
210 |
+ } |
|
211 |
+ } |
|
212 |
+ }; |
|
213 |
+ fetchPhotosTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.GROUP_PHOTO_LIST_URL); |
|
214 |
+ } |
|
106 | 215 |
class SavePhotoTask extends AsyncTask<String, Integer, Boolean> { |
107 | 216 |
|
108 | 217 |
private Context context; |
@@ -34,6 +34,7 @@ public class DetailPhotoPageAdapter extends PagerAdapter { |
||
34 | 34 |
private Context context; |
35 | 35 |
private LayoutInflater inflater; |
36 | 36 |
private DisplayImageOptions options; |
37 |
+ private boolean fromGroup; |
|
37 | 38 |
|
38 | 39 |
public DetailPhotoPageAdapter(Context context, ArrayList<GroupPhotoItem> photoList) { |
39 | 40 |
this.context = context; |
@@ -71,8 +72,19 @@ public class DetailPhotoPageAdapter extends PagerAdapter { |
||
71 | 72 |
public void onClick(View v) { |
72 | 73 |
GroupPhotoItem photoItem = photoList.get(position); |
73 | 74 |
Intent intent = new Intent(context, PhotoFullScreenActivity.class); |
74 |
- intent.putExtra("list",photoList); |
|
75 |
+ ArrayList<GroupPhotoItem> groupPhotoList = new ArrayList<>(); |
|
76 |
+ if(photoList.size()<300){ |
|
77 |
+ groupPhotoList.addAll(photoList); |
|
78 |
+ }else{ |
|
79 |
+ if(position>10){ |
|
80 |
+ groupPhotoList.addAll(photoList.subList(position-9,position+290>photoList.size()?photoList.size():position+290)); |
|
81 |
+ }else{ |
|
82 |
+ groupPhotoList.addAll(photoList.subList(0,300)); |
|
83 |
+ } |
|
84 |
+ } |
|
85 |
+ intent.putExtra("list",groupPhotoList); |
|
75 | 86 |
intent.putExtra("photo_item",photoItem); |
87 |
+ intent.putExtra("fromGroup",fromGroup); |
|
76 | 88 |
context.startActivity(intent); |
77 | 89 |
} |
78 | 90 |
}); |
@@ -123,4 +135,8 @@ public class DetailPhotoPageAdapter extends PagerAdapter { |
||
123 | 135 |
notifyDataSetChanged(); |
124 | 136 |
} |
125 | 137 |
|
138 |
+ public void setFromGroup(boolean fromGroup){ |
|
139 |
+ this.fromGroup = fromGroup; |
|
140 |
+ } |
|
141 |
+ |
|
126 | 142 |
} |
@@ -149,4 +149,9 @@ public class FullScreenPhotoPageAdapter extends PagerAdapter implements TouchIma |
||
149 | 149 |
public void onZoomModeChanged(boolean isZoomed) { |
150 | 150 |
pager.setLocked(isZoomed); |
151 | 151 |
} |
152 |
+ |
|
153 |
+ public void addPhotos(ArrayList<GroupPhotoItem> photoItems){ |
|
154 |
+ photoList.addAll(photoItems); |
|
155 |
+ notifyDataSetChanged(); |
|
156 |
+ } |
|
152 | 157 |
} |