use of us.koller.cameraroll.data.models.VirtualAlbum in project Camera-Roll-Android-App by kollerlukas.
the class VirtualAlbumsActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_virtual_albums);
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
virtualAlbums = Provider.getVirtualAlbums(this);
final TextView emptyStateText = findViewById(R.id.empty_state_text);
if (virtualAlbums.size() == 0) {
emptyStateText.setText(R.string.no_virtual_albums);
emptyStateText.setVisibility(View.VISIBLE);
}
final int accentColor = theme.getAccentColor(this);
final int toolbarTitleColor = theme.getTextColorPrimary(this);
final String toolbarTitle = String.valueOf(toolbar.getTitle());
final RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new RecyclerViewAdapter(virtualAlbums);
onVirtualAlbumChangedListener = new RecyclerViewAdapter.OnVirtualAlbumChangedListener() {
@Override
public void onVirtualAlbumChanged(VirtualAlbum album) {
menu.findItem(R.id.add_virtual_album).setVisible(album == null);
if (album != null) {
toolbar.setTitle(album.getName());
toolbar.setTitleTextColor(accentColor);
} else {
toolbar.setTitle(toolbarTitle);
toolbar.setTitleTextColor(toolbarTitleColor);
}
if (album == null) {
if (virtualAlbums.size() == 0) {
emptyStateText.setText(R.string.no_virtual_albums);
emptyStateText.setVisibility(View.VISIBLE);
} else {
emptyStateText.setVisibility(View.GONE);
}
} else {
if (album.getDirectories().size() == 0) {
emptyStateText.setText(R.string.no_paths);
emptyStateText.setVisibility(View.VISIBLE);
} else {
emptyStateText.setVisibility(View.GONE);
}
}
}
};
adapter.setOnVirtualAlbumChangedListener(onVirtualAlbumChangedListener);
recyclerView.setAdapter(adapter);
final ViewGroup rootView = findViewById(R.id.root_view);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
rootView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
@RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
public WindowInsets onApplyWindowInsets(View view, WindowInsets insets) {
toolbar.setPadding(toolbar.getPaddingStart() + insets.getSystemWindowInsetLeft(), toolbar.getPaddingTop() + insets.getSystemWindowInsetTop(), toolbar.getPaddingEnd() + insets.getSystemWindowInsetRight(), toolbar.getPaddingBottom());
recyclerView.setPadding(recyclerView.getPaddingStart() + insets.getSystemWindowInsetLeft(), recyclerView.getPaddingTop(), recyclerView.getPaddingEnd() + insets.getSystemWindowInsetRight(), recyclerView.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// clear this listener so insets aren't re-applied
rootView.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
} else {
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
// hacky way of getting window insets on pre-Lollipop
int[] screenSize = Util.getScreenSize(VirtualAlbumsActivity.this);
int[] windowInsets = new int[] { Math.abs(screenSize[0] - rootView.getLeft()), Math.abs(screenSize[1] - rootView.getTop()), Math.abs(screenSize[2] - rootView.getRight()), Math.abs(screenSize[3] - rootView.getBottom()) };
toolbar.setPadding(toolbar.getPaddingStart() + windowInsets[0], toolbar.getPaddingTop() + windowInsets[1], toolbar.getPaddingEnd() + windowInsets[2], toolbar.getPaddingBottom());
recyclerView.setPadding(recyclerView.getPaddingStart() + windowInsets[0], recyclerView.getPaddingTop(), recyclerView.getPaddingEnd() + windowInsets[2], recyclerView.getPaddingBottom() + windowInsets[3]);
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
// needed to achieve transparent statusBar in landscape; don't ask me why, but its working
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
use of us.koller.cameraroll.data.models.VirtualAlbum in project Camera-Roll-Android-App by kollerlukas.
the class MediaProvider method getAlbumsWithVirtualDirectories.
public static ArrayList<Album> getAlbumsWithVirtualDirectories(Activity context) {
Settings s = Settings.getInstance(context);
boolean virtualDirs = s.getVirtualDirectories();
if (!virtualDirs) {
return getAlbums();
}
ArrayList<VirtualAlbum> virtualAlbums = getVirtualAlbums(context);
ArrayList<Album> albums = getAlbums();
if (albums == null || virtualAlbums == null) {
return albums;
}
// noinspection unchecked
albums = (ArrayList<Album>) getAlbums().clone();
ArrayList<Album> albumsWithVirtualDirs = new ArrayList<>();
for (int i = virtualAlbums.size() - 1; i >= 0; i--) {
VirtualAlbum virtualAlbum = virtualAlbums.get(i);
if (virtualAlbum.getDirectories().size() > 0) {
virtualAlbum.create(context, albums);
if (virtualAlbum.getAlbumItems().size() > 0) {
albumsWithVirtualDirs.add(virtualAlbum);
}
}
}
albumsWithVirtualDirs.addAll(albums);
for (int i = albumsWithVirtualDirs.size() - 1; i >= 0; i--) {
Album album = albumsWithVirtualDirs.get(i);
if (!(album instanceof VirtualAlbum)) {
for (int k = 0; k < virtualAlbums.size(); k++) {
if (virtualAlbums.get(k).contains(album.getPath())) {
albumsWithVirtualDirs.remove(i);
break;
}
}
}
}
SortUtil.sortAlbums(context, albumsWithVirtualDirs);
return albumsWithVirtualDirs;
}
use of us.koller.cameraroll.data.models.VirtualAlbum in project Camera-Roll-Android-App by kollerlukas.
the class MediaProvider method loadAlbum.
public static void loadAlbum(final Activity context, final String path, final OnAlbumLoadedCallback callback) {
if (path == null) {
context.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.onAlbumLoaded(null);
}
});
return;
}
if (albums == null) {
Settings s = Settings.getInstance(context);
boolean hiddenFolders = s.getHiddenFolders();
new MediaProvider(context).loadAlbums(context, hiddenFolders, new OnMediaLoadedCallback() {
@Override
public void onMediaLoaded(ArrayList<Album> albums) {
loadAlbum(context, path, callback);
}
@Override
public void timeout() {
callback.onAlbumLoaded(getErrorAlbum());
}
@Override
public void needPermission() {
callback.onAlbumLoaded(getErrorAlbum());
}
});
} else {
if (path.startsWith(VirtualAlbum.VIRTUAL_ALBUMS_DIR)) {
ArrayList<VirtualAlbum> virtualDirectories = getVirtualAlbums(context);
for (int i = 0; i < virtualDirectories.size(); i++) {
if (virtualDirectories.get(i).getPath().equals(path)) {
final VirtualAlbum album = virtualDirectories.get(i);
album.create(context, albums);
context.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.onAlbumLoaded(album);
}
});
return;
}
}
} else if (path.equals(SINGLE_FOLDER_PATH)) {
final Album album = new Album().setPath(MediaProvider.SINGLE_FOLDER_PATH);
for (int i = 0; i < albums.size(); i++) {
album.getAlbumItems().addAll(albums.get(i).getAlbumItems());
}
int sortBy = Settings.getInstance(context).sortAlbumsBy();
SortUtil.sort(album.getAlbumItems(), sortBy);
context.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.onAlbumLoaded(album);
}
});
} else {
for (int i = 0; i < albums.size(); i++) {
if (albums.get(i).getPath().equals(path)) {
final Album album = albums.get(i);
context.runOnUiThread(new Runnable() {
@Override
public void run() {
callback.onAlbumLoaded(album);
}
});
return;
}
}
}
}
}
use of us.koller.cameraroll.data.models.VirtualAlbum in project Camera-Roll-Android-App by kollerlukas.
the class AlbumHolder method setAlbum.
public void setAlbum(Album album) {
if (album == null) {
// Error album
album = MediaProvider.getErrorAlbum();
}
this.album = album;
TextView nameTv = itemView.findViewById(R.id.name);
nameTv.setText(album.getName());
// to fix ellipsize
nameTv.requestLayout();
// pinned indicator
/*Drawable pinIndicator = null;
if (album.pinned) {
pinIndicator = AppCompatResources
.getDrawable(getContext(), R.drawable.pin_indicator);
if (pinIndicator != null) {
int color = nameTv.getTextColors().getDefaultColor();
DrawableCompat.wrap(pinIndicator);
DrawableCompat.setTint(pinIndicator, color);
DrawableCompat.unwrap(pinIndicator);
}
}
nameTv.setCompoundDrawablesRelativeWithIntrinsicBounds(
null, null, pinIndicator, null);*/
// set album itemCount
int itemCount = album.getAlbumItems().size();
boolean oneItem = itemCount == 1;
String count = getContext().getString(oneItem ? R.string.item_count : R.string.items_count, itemCount);
((TextView) itemView.findViewById(R.id.count)).setText(Html.fromHtml(count));
ImageView hiddenFolderIndicator = itemView.findViewById(R.id.hidden_folder_indicator);
if (hiddenFolderIndicator != null) {
hiddenFolderIndicator.setVisibility(album.isHidden() ? View.VISIBLE : View.GONE);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !(album instanceof VirtualAlbum)) {
ImageView removableStorageIndicator = itemView.findViewById(R.id.removable_storage_indicator);
if (removableStorageIndicator != null) {
try {
boolean removable = Environment.isExternalStorageRemovable(new File(album.getPath()));
removableStorageIndicator.setVisibility(removable ? View.VISIBLE : View.GONE);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
}
}
use of us.koller.cameraroll.data.models.VirtualAlbum in project Camera-Roll-Android-App by kollerlukas.
the class VirtualAlbumsActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
onBackPressed();
break;
case R.id.add_virtual_album:
AlertDialog dialog = VirtualAlbum.Util.getCreateVirtualAlbumDialog(this, new VirtualAlbum.Util.OnCreateVirtualAlbumCallback() {
@Override
public void onVirtualAlbumCreated(VirtualAlbum virtualAlbum) {
virtualAlbums = Provider.getVirtualAlbums(VirtualAlbumsActivity.this);
adapter.notifyDataSetChanged();
onVirtualAlbumChangedListener.onVirtualAlbumChanged(null);
}
});
dialog.show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
Aggregations