summaryrefslogtreecommitdiff
path: root/app/src/main/java/uk/co/blatech/blaupload/ImagePager.java
blob: 0191c520974156763b05862a93e1ab1854de97ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package uk.co.blatech.blaupload;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import com.squareup.otto.Subscribe;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import uk.co.blatech.blaupload.R;
import uk.co.blatech.blaupload.data.ImageItem;
import uk.co.blatech.blaupload.ui.ImagePagerAdapter;
import uk.co.blatech.blaupload.util.EventBus;
import uk.co.blatech.blaupload.util.ImageLoader;
import uk.co.blatech.blaupload.util.ImageLoaderResultEvent;

public class ImagePager extends Activity {


    private ViewPager mViewPager;
    private JSONArray json;
    private ArrayList<String> urls;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mViewPager = new ViewPager(this);
        setContentView(mViewPager);
        EventBus.getInstance().register(this);
        urls = new ArrayList<String>();
        String jsonText = getIntent().getStringExtra("json");
        int id = getIntent().getIntExtra("position", 0);

        try {
            json = new JSONArray(jsonText);
        } catch (JSONException e) {
            //TODO: Error handling if we got something other than JSON
            Log.e(ImagePager.class.toString(), "Failed to parse JSON");
            e.printStackTrace();
        }

        for (int i = 0; i < json.length(); i++) {
            try {
                JSONObject item = json.getJSONObject(i);
                urls.add("http://www.blaupload.co.uk/"+item.getString("filename"));
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }

        ImagePagerAdapter adapter = new ImagePagerAdapter(ImagePager.this, urls);
        mViewPager.setAdapter(adapter);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.image_pager, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }


}