securesmartcam / app / src / main / java / org / witness / obscuracam / ui / AlbumsActivity.java @ 41590feb
History | View | Annotate | Download (5.45 KB)
1 |
package org.witness.obscuracam.ui; |
---|---|
2 |
|
3 |
import android.content.Intent; |
4 |
import android.os.Build; |
5 |
import android.os.Bundle; |
6 |
import android.support.v7.app.AppCompatActivity; |
7 |
import android.support.v7.widget.RecyclerView; |
8 |
import android.support.v7.widget.Toolbar; |
9 |
import android.view.MenuItem; |
10 |
import android.view.View; |
11 |
import android.widget.Button; |
12 |
|
13 |
import org.witness.obscuracam.ui.adapters.AlbumAdapter; |
14 |
import org.witness.obscuracam.ui.adapters.GalleryCursorRecyclerViewAdapter; |
15 |
import org.witness.sscphase1.R; |
16 |
|
17 |
public class AlbumsActivity extends AppCompatActivity implements AlbumAdapter.AlbumAdapterListener, GalleryCursorRecyclerViewAdapter.GalleryCursorRecyclerViewAdapterListener { |
18 |
|
19 |
private static final boolean LOGGING = false; |
20 |
private static final String LOGTAG = "AlbumsActivity"; |
21 |
|
22 |
private static final int PICK_EXTERNAL_REQUEST = 5; |
23 |
|
24 |
private View mRootView; |
25 |
private RecyclerView mRecyclerView;
|
26 |
private AlbumLayoutManager mLayoutManager;
|
27 |
private View mLayoutGalleryInfo; |
28 |
|
29 |
@Override
|
30 |
protected void onCreate(Bundle savedInstanceState) { |
31 |
super.onCreate(savedInstanceState);
|
32 |
setContentView(R.layout.activity_albums); |
33 |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); |
34 |
setSupportActionBar(toolbar); |
35 |
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
36 |
|
37 |
mRootView = findViewById(R.id.main_content); |
38 |
|
39 |
mLayoutGalleryInfo = mRootView.findViewById(R.id.gallery_info); |
40 |
Button btnOk = (Button) mLayoutGalleryInfo.findViewById(R.id.btnGalleryInfoOk); |
41 |
btnOk.setOnClickListener(new View.OnClickListener() { |
42 |
@Override
|
43 |
public void onClick(View view) { |
44 |
//TODO App.getInstance().getSettings().setSkipGalleryInfo(true);
|
45 |
mLayoutGalleryInfo.setVisibility(View.GONE);
|
46 |
} |
47 |
}); |
48 |
mLayoutGalleryInfo.setVisibility(View.GONE);
|
49 |
|
50 |
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_albums); |
51 |
int colWidth = getResources().getDimensionPixelSize(R.dimen.photo_column_size);
|
52 |
mLayoutManager = new AlbumLayoutManager(this, colWidth); |
53 |
mRecyclerView.setLayoutManager(mLayoutManager); |
54 |
|
55 |
setAlbumAdapter(); |
56 |
} |
57 |
|
58 |
@Override
|
59 |
protected void onResume() { |
60 |
super.onResume();
|
61 |
if (mRecyclerView != null && mRecyclerView.getAdapter() instanceof GalleryCursorRecyclerViewAdapter) { |
62 |
((GalleryCursorRecyclerViewAdapter) mRecyclerView.getAdapter()).update(); |
63 |
} |
64 |
} |
65 |
@Override
|
66 |
public boolean onOptionsItemSelected(MenuItem item) { |
67 |
if (item.getItemId() == android.R.id.home) {
|
68 |
if (mRecyclerView.getAdapter() instanceof GalleryCursorRecyclerViewAdapter) { |
69 |
setAlbumAdapter(); |
70 |
return true; |
71 |
} |
72 |
finish(); |
73 |
return true; |
74 |
} |
75 |
return super.onOptionsItemSelected(item); |
76 |
} |
77 |
|
78 |
@Override
|
79 |
public void onAlbumSelected(String id, String albumName) { |
80 |
getSupportActionBar().setTitle(albumName); |
81 |
setPhotosAdapter(id, false, false); |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public void onPickExternalSelected() { |
86 |
Intent intent = new Intent(Build.VERSION.SDK_INT >= 19 ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT); |
87 |
intent.addCategory(Intent.CATEGORY_OPENABLE); |
88 |
intent.setType("image/*");
|
89 |
startActivityForResult(intent, PICK_EXTERNAL_REQUEST); |
90 |
} |
91 |
|
92 |
@Override
|
93 |
public void onPhotoSelected(String photo, final View thumbView) { |
94 |
Intent data = new Intent();
|
95 |
data.putExtra("uri", photo);
|
96 |
data.putExtra("video", false); |
97 |
setResult(RESULT_OK, data); |
98 |
finish(); |
99 |
} |
100 |
|
101 |
@Override
|
102 |
public void onVideoSelected(String video, final View thumbView) { |
103 |
Intent data = new Intent();
|
104 |
data.putExtra("uri", video);
|
105 |
data.putExtra("video", true); |
106 |
setResult(RESULT_OK, data); |
107 |
finish(); |
108 |
} |
109 |
|
110 |
@Override
|
111 |
public void onCameraSelected() { |
112 |
} |
113 |
|
114 |
@Override
|
115 |
public void onAlbumsSelected() { |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public void onBackPressed() { |
120 |
if (mRecyclerView.getAdapter() instanceof GalleryCursorRecyclerViewAdapter) { |
121 |
setAlbumAdapter(); |
122 |
return;
|
123 |
} |
124 |
super.onBackPressed();
|
125 |
} |
126 |
|
127 |
private void setAlbumAdapter() { |
128 |
getSupportActionBar().setTitle(R.string.title_albums); |
129 |
mRecyclerView.setLayoutManager(mLayoutManager); |
130 |
AlbumAdapter adapter = new AlbumAdapter(this, true); |
131 |
adapter.setListener(this);
|
132 |
int colWidth = getResources().getDimensionPixelSize(R.dimen.album_column_size);
|
133 |
mLayoutManager.setColumnWidth(colWidth); |
134 |
mRecyclerView.setAdapter(adapter); |
135 |
} |
136 |
|
137 |
private void setPhotosAdapter(String album, boolean showCamera, boolean showAlbums) { |
138 |
mRecyclerView.setLayoutManager(mLayoutManager); |
139 |
GalleryCursorRecyclerViewAdapter adapter = new GalleryCursorRecyclerViewAdapter(this, album, showCamera, showAlbums); |
140 |
adapter.setListener(this);
|
141 |
int colWidth = getResources().getDimensionPixelSize(R.dimen.photo_column_size);
|
142 |
mLayoutManager.setColumnWidth(colWidth); |
143 |
mRecyclerView.setAdapter(adapter); |
144 |
} |
145 |
|
146 |
@Override
|
147 |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
148 |
if (requestCode == PICK_EXTERNAL_REQUEST) {
|
149 |
if (resultCode == RESULT_OK && data != null && data.getData() != null) { |
150 |
onPhotoSelected(data.getData().toString(), null); //TODO - video |
151 |
} |
152 |
} |
153 |
} |
154 |
} |