Search in sources :

Example 1 with VirtualAlbum

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);
}
Also used : ViewGroup(android.view.ViewGroup) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) WindowInsets(android.view.WindowInsets) RequiresApi(android.support.annotation.RequiresApi) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ViewTreeObserver(android.view.ViewTreeObserver) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with VirtualAlbum

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;
}
Also used : ArrayList(java.util.ArrayList) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Settings(us.koller.cameraroll.data.Settings)

Example 3 with VirtualAlbum

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;
                }
            }
        }
    }
}
Also used : VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Album(us.koller.cameraroll.data.models.Album) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) Settings(us.koller.cameraroll.data.Settings)

Example 4 with VirtualAlbum

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();
            }
        }
    }
}
Also used : TextView(android.widget.TextView) ImageView(android.widget.ImageView) ParallaxImageView(us.koller.cameraroll.ui.widget.ParallaxImageView) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum) File(java.io.File)

Example 5 with VirtualAlbum

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);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Util(us.koller.cameraroll.util.Util) VirtualAlbum(us.koller.cameraroll.data.models.VirtualAlbum)

Aggregations

VirtualAlbum (us.koller.cameraroll.data.models.VirtualAlbum)5 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Settings (us.koller.cameraroll.data.Settings)2 Album (us.koller.cameraroll.data.models.Album)2 RequiresApi (android.support.annotation.RequiresApi)1 ActionBar (android.support.v7.app.ActionBar)1 AlertDialog (android.support.v7.app.AlertDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ViewTreeObserver (android.view.ViewTreeObserver)1 WindowInsets (android.view.WindowInsets)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 ParallaxImageView (us.koller.cameraroll.ui.widget.ParallaxImageView)1 Util (us.koller.cameraroll.util.Util)1