예제 #1
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.action_search:
        return true;

      case R.id.action_top:
        Singleton.getInstance().clearAllPeekContent();
        adapter.notifyDataSetChanged();
        new GetTask().execute("http://1-dot-august-clover-86805.appspot.com/Get", "", 1);
        sort_top = true;
        return true;

      case R.id.action_new:
        Singleton.getInstance().clearAllPeekContent();
        adapter.notifyDataSetChanged();
        new GetTask().execute("http://1-dot-august-clover-86805.appspot.com/Get", "");
        sort_latest = true;
        return true;

      default:
        break;
    }

    return false;
  }
예제 #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    View root = inflater.inflate(R.layout.fragment_other, container, false);
    this.root = root;

    listview = (ListView) root.findViewById(R.id.peekMediaFeedListView);
    adapter =
        new MediaArrayAdapter(
            this.getActivity(),
            android.R.layout.simple_list_item_1,
            Singleton.getInstance().getPeekMediaFeed(),
            true);
    listview.setAdapter(adapter);
    OnItemClickListener clickListener =
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent;
            intent = new Intent(getActivity(), focusedMediaContentPage.class);

            // Load the data that this page will be displaying
            intent.putExtra("Position", position);
            intent.putExtra("Interactable", false);

            getActivity().startActivity(intent);
          }
        };
    listview.setOnItemClickListener(clickListener);
    listview.setEmptyView((LinearLayout) root.findViewById(R.id.emptyNotification));

    final SwipeRefreshLayout swipeView =
        (SwipeRefreshLayout) root.findViewById(R.id.swipePeekMediaFeed);
    swipe = swipeView;
    swipeView.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            Singleton.getInstance().clearAllPeekContent();
            adapter.notifyDataSetChanged();
            new GetTask()
                .execute("http://1-dot-august-clover-86805.appspot.com/Get", address, sortVal);
          }
        });

    promptForLocation();

    // new GetTask().execute("http://1-dot-august-clover-86805.appspot.com/Get", "", sortVal);

    return root;
  }
예제 #3
0
    @Override
    protected void onPostExecute(JSONObject result) {
      swipe.setRefreshing(false);

      if (result == null) {
        // Something went wrong. We need to notify the user.
        sendAlertFailure("We were unable to retrieve any data from the server at this time.");
        return;
      }

      if (JSONMessage.getID(result) == -1) {
        // Indicates an error.
        sendAlertFailure("We couldn't find that location. Did you spell the address correctly?");
        return;
      }

      // Return the array of string representation pictures
      String[] pics = JSONMessage.clientGetImage(result);
      String[] dates = JSONMessage.clientGetDate(result);
      Integer[] ratings = JSONMessage.clientGetRating(result);
      Integer[] ids = JSONMessage.clientGetID(result);
      int insertIndex = 0;
      for (int i = 0; i < pics.length; i++) {
        // We're at the end of the stream. Return.
        if (pics[i] == "null") return;

        if (dates[i] == "null") continue;

        if (Singleton.getInstance().containsMediaContentWithId(ids[i])) {
          MediaContent c = Singleton.getInstance().getMediaContent(ids[i]);
          c.setRating(ratings[i]);
          adapter.notifyDataSetChanged();
          continue;
        }

        Bitmap b = JSONMessage.decodeBase64(pics[i]);

        SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S");
        d.setTimeZone(TimeZone.getTimeZone("GMT"));
        Date date = null;
        try {
          date = d.parse(dates[i]);
        } catch (ParseException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        MediaContent newContent =
            new MediaContent(false, ids[i].intValue(), date, b, ratings[i].intValue());
        adapter.insert(newContent, insertIndex++);
        adapter.notifyDataSetChanged();
      }

      if (sort_top) {
        adapter.sort(
            new Comparator<MediaContent>() {
              @Override
              public int compare(MediaContent lhs, MediaContent rhs) {
                return rhs.getRating() - lhs.getRating();
              }
            });

        sort_top = false;
      }

      if (sort_latest) {
        adapter.sort(
            new Comparator<MediaContent>() {
              @Override
              public int compare(MediaContent lhs, MediaContent rhs) {
                return rhs.getTimestamp().compareTo(lhs.getTimestamp());
              }
            });

        sort_latest = false;
      }
    }