Android Open Source - connexus-android Stream Grid Fragment






From Project

Back to project page connexus-android.

License

The source code is released under:

Apache License

If you think the Android project connexus-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2013 Zach Whaley, Trevor Latson
 */* ww w  .jav a 2 s . c om*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ginger.connexus.fragment;

import ginger.connexus.activity.ImageGridActivity;
import ginger.connexus.model.ConnexusStream;
import ginger.connexus.network.ConnexusApi;
import ginger.connexus.network.RequestAllStreams;
import ginger.connexus.network.RequestNearbyStreams;
import ginger.connexus.network.RequestSubscribedStreams;

import java.util.ArrayList;

import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast;

import com.octo.android.robospice.persistence.exception.SpiceException;
import com.octo.android.robospice.request.listener.RequestListener;
import com.octo.android.robospice.request.retrofit.RetrofitSpiceRequest;

public class StreamGridFragment extends GridFragment {

    private static final String TAG = StreamGridFragment.class.toString();

    public static final String REQUEST = "request";
    public static final String LOCATION = "location";
    public static final String EMAIL = "email";
    public static final int REQUEST_ALL = 0;
    public static final int REQUEST_SUBSCRIBED = 1;
    public static final int REQUEST_NEARBY = 2;
    public static final int REQUEST_SEARCH = 100;

    private RetrofitSpiceRequest<ConnexusStream.List, ConnexusApi> mStreamRequest;
    private ConnexusStream.List mStreams;

    /**
     * Empty constructor as per the Fragment documentation
     */
    public StreamGridFragment() {
    }

    public static StreamGridFragment newInstance(final Intent intent, Bundle arguments) {
        StreamGridFragment fragment = new StreamGridFragment();
        arguments.putParcelable(FORWARD_INTENT, intent);
        fragment.setArguments(arguments);
        return fragment;
    }

    public void setStreams(ConnexusStream.List streams) {
        this.mStreams = streams;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        reloadFromArguments(getArguments());
    }

    private void reloadFromArguments(Bundle arguments) {
        mIntent = (Intent) arguments.getParcelable(FORWARD_INTENT);
        final int request = arguments.getInt(REQUEST, -1);
        switch (request) {
            case REQUEST_ALL:
                mStreamRequest = new RequestAllStreams();
                break;
            case REQUEST_SUBSCRIBED:
                String email = arguments.getString(EMAIL);
                Log.i(TAG, "mystreams " + email);
                mStreamRequest = new RequestSubscribedStreams(email);
                break;
            case REQUEST_NEARBY:
                Location location = (Location) arguments.getParcelable(LOCATION);
                float lat = (float) location.getLatitude();
                float lng = (float) location.getLongitude();
                Log.i(TAG, "lat " + lat + " lng " + lng);
                mStreamRequest = new RequestNearbyStreams(lat, lng);
                break;
            case REQUEST_SEARCH:
                ArrayList<String> imageUrls = new ArrayList<String>(mStreams.size());
                for (ConnexusStream stream : mStreams) {
                    imageUrls.add(stream.getCoverUrl());
                }
                reloadImages(imageUrls);
                return;
            default:
                throw new UnsupportedOperationException(TAG);
        }
        getSpiceManager().execute(mStreamRequest, new ConnexusStreamRequestListener());
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        ConnexusStream stream = mStreams.get(position);
        mIntent.putExtra(ImageGridActivity.EXTRA_STREAM, stream.getId());
        mIntent.putExtra(ImageGridActivity.EXTRA_STREAM_NAME, stream.getName());
        startActivity(mIntent);
    }

    private final class ConnexusStreamRequestListener implements RequestListener<ConnexusStream.List> {

        @Override
        public void onRequestFailure(SpiceException spiceException) {
            Log.w(TAG, "onRequestFailure: " + spiceException.toString());
            Toast.makeText(getActivity(), "Error occured:" + spiceException.toString(), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRequestSuccess(final ConnexusStream.List result) {
            mStreams = result;
            ArrayList<String> imageUrls = new ArrayList<String>(result.size());
            for (ConnexusStream stream : result) {
                imageUrls.add(stream.getCoverUrl());
            }
            StreamGridFragment.this.reloadImages(imageUrls);
        }
    }

}




Java Source Code List

android.UnusedStub.java
ginger.connexus.Connexus.java
ginger.connexus.activity.AuthActivity.java
ginger.connexus.activity.BaseActivity.java
ginger.connexus.activity.ImageDetailActivity.java
ginger.connexus.activity.ImageGridActivity.java
ginger.connexus.activity.MainActivity.java
ginger.connexus.activity.SearchableActivity.java
ginger.connexus.adapter.ImageAdapter.java
ginger.connexus.fragment.ChooseAccountFragment.java
ginger.connexus.fragment.GridFragment.java
ginger.connexus.fragment.ImageDetailFragment.java
ginger.connexus.fragment.ImageGridFragment.java
ginger.connexus.fragment.SpiceFragment.java
ginger.connexus.fragment.StreamGridFragment.java
ginger.connexus.model.ConnexusImage.java
ginger.connexus.model.ConnexusStream.java
ginger.connexus.network.ConnexusApi.java
ginger.connexus.network.RequestAllStreams.java
ginger.connexus.network.RequestNearbyStreams.java
ginger.connexus.network.RequestStreamImages.java
ginger.connexus.network.RequestSubscribedStreams.java
ginger.connexus.network.RequestUploadURL.java
ginger.connexus.network.UploadImage.java
ginger.connexus.service.ConnexusService.java
ginger.connexus.ui.RecyclingBitmapDrawable.java
ginger.connexus.ui.RecyclingImageView.java
ginger.connexus.util.AccountUtils.java
ginger.connexus.util.AsyncTask.java
ginger.connexus.util.DiskLruCache.java
ginger.connexus.util.ImageCache.java
ginger.connexus.util.ImageFetcher.java
ginger.connexus.util.ImageResizer.java
ginger.connexus.util.ImageWorker.java
ginger.connexus.util.Images.java
ginger.connexus.util.Utils.java