Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.62 KB | None | 0 0
  1. package com.gauss.movv.main.fragment;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.annotation.NonNull;
  6. import android.support.annotation.Nullable;
  7. import android.support.v4.widget.SwipeRefreshLayout;
  8. import android.util.Log;
  9. import android.view.LayoutInflater;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.AbsListView;
  13. import android.widget.ImageButton;
  14. import android.widget.ListView;
  15. import android.widget.RadioButton;
  16. import android.widget.RadioGroup;
  17. import android.widget.Toast;
  18.  
  19. import com.gauss.movv.R;
  20. import com.gauss.movv.base.fragment.BaseFragment;
  21. import com.gauss.movv.camera.activity.CameraActivity;
  22. import com.gauss.movv.commons.BusProvider;
  23. import com.gauss.movv.commons.MovvService;
  24. import com.gauss.movv.commons.PreferenceHelper;
  25. import com.gauss.movv.inbox.activity.InboxActivity;
  26. import com.gauss.movv.main.adapter.HomeFeedAdapter;
  27. import com.gauss.movv.main.model.FeedRequest;
  28. import com.gauss.movv.main.model.FeedResponse;
  29. import com.gauss.movv.main.model.HomeFeedModel;
  30. import com.gauss.movv.main.model.ProductsDataModel;
  31. import com.gauss.movv.news.activity.NewsActivity;
  32. import com.gauss.movv.profile.activity.ProfileFinalActivity;
  33. import com.gauss.movv.search.activity.SearchActivity;
  34. import com.gauss.movv.users.model.LoginRequest;
  35. import com.squareup.otto.Subscribe;
  36.  
  37. import java.util.ArrayList;
  38.  
  39. import retrofit.RetrofitError;
  40.  
  41. /**
  42. * Created by Laptop on 8.6.2015..
  43. */
  44.  
  45. public class MainFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener, View.OnClickListener {
  46.  
  47. public static final String DETAILS_KEY = "details_key";
  48.  
  49.  
  50. private ListView mPostsListView;
  51. private SwipeRefreshLayout mSwipeRefreshLayout;
  52. ArrayList<ProductsDataModel> mProducts = new ArrayList<>();
  53.  
  54. private RadioGroup mNavigationBottomRadioGroup;
  55. private RadioButton mHomeRadioButton;
  56. private RadioButton mNewsRadioButton;
  57. private RadioButton mSearchRadioButton;
  58. private RadioButton mProfileRadioButton;
  59. private RadioButton mInboxRadioButton;
  60. FeedRequest feedRequest;
  61. private HomeFeedAdapter homeFeedAdapter;
  62.  
  63.  
  64. private ImageButton mActionButton;
  65. private int mScrollState = AbsListView.OnScrollListener.SCROLL_STATE_IDLE;
  66.  
  67.  
  68. @Override
  69. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  70.  
  71. return inflater.inflate(R.layout.fragment_main, container, false);
  72.  
  73.  
  74. }
  75.  
  76. @Override
  77. public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  78. super.onViewCreated(view, savedInstanceState);
  79. prepareUI(view);
  80. initListeners();
  81. if (PreferenceHelper.getUserId(getActivity().getApplicationContext()) != null)
  82. Toast.makeText(getActivity(), "tu si", Toast.LENGTH_SHORT).show();
  83.  
  84. feedRequest = new FeedRequest();
  85. feedRequest.setUserId(Long.valueOf(PreferenceHelper.getUserId(getActivity())));
  86.  
  87. setAdapter();
  88.  
  89.  
  90. // DataModel data[] = new DataModel[]{
  91. // new DataModel(R.drawable.user1, "@ivan", "Zagreb, Croatia", " 10m", "Sony Xperia Z1", "technology, phone, mobile", " 21", " 5", "$120", R.drawable.soccer_shoes, R.raw.small_video),
  92. // new DataModel(R.drawable.user2, "@john", "Paris, France", " 15m", "Lenovo B596", "technology, laptop, computer", " 30", " 8", "$550", R.drawable.soccer_shoes, R.raw.small_video),
  93. // new DataModel(R.drawable.user3, "@melisa", "Split, Croatia", " 20m", "Samsung S4", "technology, phone, mobile", " 22", " 11", "$150", R.drawable.soccer_shoes, R.raw.small_video),
  94. // new DataModel(R.drawable.user1, "@tibor", "Budimpesta, Hungary", " 10m", "Sony Xperia Z1", "technology, phone, mobile", " 21", " 5", "$120", R.drawable.soccer_shoes, R.raw.small_video),
  95. // new DataModel(R.drawable.user2, "@mark", "Sarajevo, BiH", " 15m", "Lenovo B596", "technology, laptop, computer", " 30", " 8", "$550", R.drawable.soccer_shoes, R.raw.small_video),
  96. // new DataModel(R.drawable.user3, "@helen", "London, England", " 20m", "Samsung S4", "technology, phone, mobile", " 22", " 11", "$150", R.drawable.soccer_shoes, R.raw.small_video),
  97. //
  98. // };
  99. //
  100. // final PostsListsAdapter adapter = new PostsListsAdapter(getActivity(), R.layout.list_item_post, data);
  101. //
  102. // mPostsListView.setAdapter(adapter);
  103. //
  104. // mPostsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  105. // @Override
  106. // public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  107. //
  108. // DataModel model = adapter.getItem(position);
  109. // Intent intent = new Intent(getActivity(), ItemDetailsActivity.class);
  110. // intent.putExtra(DETAILS_KEY, model);
  111. // startActivity(intent);
  112. //
  113. // }
  114. // });
  115.  
  116.  
  117. }
  118.  
  119. @Subscribe
  120. public void onFeedSucess(FeedResponse feedResponse) {
  121. Log.d("retrofit", "uspjesno");
  122.  
  123. mProducts = feedResponse.getProducts();
  124.  
  125. setAdapter();
  126.  
  127.  
  128. }
  129.  
  130. @Subscribe
  131. public void onFeedFailure(RetrofitError error){
  132. Log.d("retrofit", "greska");
  133. }
  134.  
  135. private void setAdapter() {
  136. if (mProducts == null) {
  137. return;
  138. }
  139.  
  140. if (mPostsListView.getAdapter() == null) {
  141. homeFeedAdapter = new HomeFeedAdapter(getActivity(), mProducts);
  142. // materialsListAdapter.setListener(this);
  143. mPostsListView.setAdapter(homeFeedAdapter);
  144. } else {
  145. homeFeedAdapter.refreshData(mProducts);
  146. }
  147. }
  148.  
  149.  
  150. @Override
  151. public void onResume() {
  152. super.onResume();
  153. BusProvider.getInstance().register(this);
  154. MovvService.getUserFeed(feedRequest);
  155. }
  156.  
  157. @Override
  158. public void onPause() {
  159. super.onPause();
  160. BusProvider.getInstance().unregister(this);
  161. }
  162.  
  163.  
  164. @Override
  165. public void onDestroy() {
  166.  
  167. super.onDestroy();
  168. }
  169.  
  170. @Override
  171. protected void prepareUI(@NonNull View layoutView) {
  172. mPostsListView = (ListView) layoutView.findViewById(R.id.adapter_view);
  173. mNavigationBottomRadioGroup = (RadioGroup) layoutView.findViewById(R.id.radio_group);
  174. mInboxRadioButton = (RadioButton) layoutView.findViewById(R.id.inbox_bar);
  175. mNewsRadioButton = (RadioButton) layoutView.findViewById(R.id.news_bar);
  176. mHomeRadioButton = (RadioButton) layoutView.findViewById(R.id.home_bar);
  177. mSearchRadioButton = (RadioButton) layoutView.findViewById(R.id.search_bar);
  178. mProfileRadioButton = (RadioButton) layoutView.findViewById(R.id.profile_bar);
  179. mActionButton = (ImageButton) layoutView.findViewById(R.id.floating_action_button);
  180. mActionButton.setBackgroundResource(0);
  181.  
  182. mSearchRadioButton.setButtonDrawable(R.mipmap.search_bar_button);
  183. mNewsRadioButton.setButtonDrawable(R.mipmap.news_bar_button);
  184. mProfileRadioButton.setButtonDrawable(R.mipmap.profile_bar_button);
  185. mInboxRadioButton.setButtonDrawable(R.mipmap.inbox_bar_button);
  186. mHomeRadioButton.setButtonDrawable(R.mipmap.home_bar_button);
  187. }
  188.  
  189. @Override
  190. protected void prepareData() {
  191.  
  192. }
  193.  
  194. protected void initListeners() {
  195. mInboxRadioButton.setOnClickListener(this);
  196. mNewsRadioButton.setOnClickListener(this);
  197. mHomeRadioButton.setOnClickListener(this);
  198. mSearchRadioButton.setOnClickListener(this);
  199. mProfileRadioButton.setOnClickListener(this);
  200. mActionButton.setOnClickListener(this);
  201. }
  202.  
  203. @Override
  204. public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  205. super.onActivityCreated(savedInstanceState);
  206. prepareData();
  207. }
  208.  
  209.  
  210. @Override
  211. public void onRefresh() {
  212. prepareData();
  213. mSwipeRefreshLayout.setRefreshing(true);
  214. }
  215.  
  216. @Override
  217. public void onClick(View view) {
  218. RadioButton checkedAnswer = (RadioButton) view.findViewById(mNavigationBottomRadioGroup.getCheckedRadioButtonId());
  219. switch (view.getId()) {
  220. case R.id.home_bar:
  221. if (checkedAnswer == mHomeRadioButton) {
  222. replaceFragment(R.id.fragment_container, new MainFragment(), false);
  223. }
  224. break;
  225. case R.id.news_bar:
  226. if (checkedAnswer == mNewsRadioButton) {
  227. Intent intent = new Intent(getActivity(), NewsActivity.class);
  228. startActivity(intent);
  229. }
  230. break;
  231. case R.id.search_bar:
  232. if (checkedAnswer == mSearchRadioButton) {
  233. Intent intent = new Intent(getActivity(), SearchActivity.class);
  234. startActivity(intent);
  235. }
  236. break;
  237. case R.id.profile_bar:
  238. if (checkedAnswer == mProfileRadioButton) {
  239. Intent intent = new Intent(getActivity(), ProfileFinalActivity.class);
  240. startActivity(intent);
  241. }
  242. break;
  243. case R.id.inbox_bar:
  244. if (checkedAnswer == mInboxRadioButton) {
  245. Intent intent = new Intent(getActivity(), InboxActivity.class);
  246. startActivity(intent);
  247. }
  248. break;
  249.  
  250. case R.id.floating_action_button:
  251. Intent intent = new Intent(getActivity(), CameraActivity.class);
  252. startActivity(intent);
  253. break;
  254.  
  255. }
  256. }
  257.  
  258.  
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement