Skip to content

Commit

Permalink
Add bottom bar
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner committed Sep 19, 2017
1 parent c3f75db commit 629d214
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Intent;
import android.database.Cursor;
import android.graphics.PorterDuff;
import android.graphics.RectF;
import android.net.Uri;
import android.os.Build;
Expand All @@ -11,6 +12,7 @@
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.design.widget.TabLayout;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
Expand All @@ -25,10 +27,12 @@
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import net.gsantner.opoc.util.SimpleMarkdownParser;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
Expand All @@ -47,41 +51,43 @@
import io.github.gsantner.memetastic.data.MemeOriginStorage;
import io.github.gsantner.memetastic.ui.GridDecoration;
import io.github.gsantner.memetastic.ui.GridRecycleAdapter;
import io.github.gsantner.memetastic.util.ActivityUtils;
import io.github.gsantner.memetastic.util.AppSettings;
import io.github.gsantner.memetastic.util.ContextUtils;
import io.github.gsantner.memetastic.util.ActivityUtils;
import io.github.gsantner.memetastic.util.ThumbnailCleanupTask;
import net.gsantner.opoc.util.SimpleMarkdownParser;

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener, TabLayout.OnTabSelectedListener {

public static final int REQUEST_LOAD_GALLERY_IMAGE = 50;
public static final int REQUEST_TAKE_CAMERA_PICTURE = 51;
public static final String IMAGE_PATH = "imagePath";
private static boolean isShowingFullscreenImage = false;
private boolean areTabsReady = false;

private static boolean _isShowingFullscreenImage = false;
private boolean _areTabsReady = false;

@BindView(R.id.toolbar)
Toolbar toolbar;
Toolbar _toolbar;

@BindView(R.id.drawer_layout)
DrawerLayout drawer;
DrawerLayout _drawer;

@BindView(R.id.main__activity__navview)
NavigationView navigationView;
NavigationView _navigationView;

@BindView(R.id.main__tabs)
TabLayout tabLayout;
TabLayout _tabLayout;

@BindView(R.id.main__activity__recycler_view)
RecyclerView recyclerMemeList;
RecyclerView _recyclerMemeList;

@BindView(R.id.main__activity__list_empty__layout)
LinearLayout emptylistLayout;
LinearLayout _emptylistLayout;

@BindView(R.id.main__activity__list_empty__text)
TextView emptylistText;
TextView _emptylistText;

@BindView(R.id.main__activity__infobar__progress)
ProgressBar _progressBar;

App app;
private String cameraPictureFilepath = "";
Expand All @@ -99,39 +105,41 @@ protected void onCreate(Bundle savedInstanceState) {
app = (App) getApplication();
ButterKnife.bind(this);

// Setup toolbar
setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.main__navdrawer__open, R.string.main__navdrawer__close);
drawer.addDrawerListener(toggle);
// Setup _toolbar
setSupportActionBar(_toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, _drawer, _toolbar, R.string.main__navdrawer__open, R.string.main__navdrawer__close);
_drawer.addDrawerListener(toggle);
toggle.syncState();
navigationView.setNavigationItemSelectedListener(this);
tabLayout.setOnTabSelectedListener(this);
_navigationView.setNavigationItemSelectedListener(this);
_tabLayout.setOnTabSelectedListener(this);

// Setup Floating Action Button
int gridColumns = ContextUtils.get().isInPortraitMode()
? app.settings.getGridColumnCountPortrait()
: app.settings.getGridColumnCountLandscape();

recyclerMemeList.setHasFixedSize(true);
recyclerMemeList.setItemViewCacheSize(app.settings.getGridColumnCountPortrait() * app.settings.getGridColumnCountLandscape() * 2);
recyclerMemeList.setDrawingCacheEnabled(true);
recyclerMemeList.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
recyclerMemeList.addItemDecoration(new GridDecoration(1.7f));
_recyclerMemeList.setHasFixedSize(true);
_recyclerMemeList.setItemViewCacheSize(app.settings.getGridColumnCountPortrait() * app.settings.getGridColumnCountLandscape() * 2);
_recyclerMemeList.setDrawingCacheEnabled(true);
_recyclerMemeList.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
_recyclerMemeList.addItemDecoration(new GridDecoration(1.7f));
RecyclerView.LayoutManager recyclerGridLayout = new GridLayoutManager(this, gridColumns);
recyclerMemeList.setLayoutManager(recyclerGridLayout);
_recyclerMemeList.setLayoutManager(recyclerGridLayout);

for (String cat : getResources().getStringArray(R.array.meme_categories)) {
TabLayout.Tab tab = tabLayout.newTab();
TabLayout.Tab tab = _tabLayout.newTab();
tab.setText(cat);
tabLayout.addTab(tab);
_tabLayout.addTab(tab);
}
areTabsReady = true;
_areTabsReady = true;
selectTab(app.settings.getLastSelectedTab(), app.settings.getDefaultMainMode());

_progressBar.getProgressDrawable().setColorFilter(ContextCompat.getColor(this, R.color.accent), PorterDuff.Mode.SRC_IN);

//
// Actions based on build type or version
//
navigationView.getMenu().findItem(R.id.action_donate_bitcoin).setVisible(!BuildConfig.IS_GPLAY_BUILD);
_navigationView.getMenu().findItem(R.id.action_donate_bitcoin).setVisible(!BuildConfig.IS_GPLAY_BUILD);


// Show first start dialog / changelog
Expand Down Expand Up @@ -159,28 +167,28 @@ private void selectTab(int pos, int mainMode) {
MenuItem navItem = null;
switch (mainMode) {
case 0:
pos = pos >= 0 ? pos : tabLayout.getTabCount() - 1;
pos = pos < tabLayout.getTabCount() ? pos : 0;
tabLayout.getTabAt(pos).select();
pos = pos >= 0 ? pos : _tabLayout.getTabCount() - 1;
pos = pos < _tabLayout.getTabCount() ? pos : 0;
_tabLayout.getTabAt(pos).select();
break;
case 1:
navItem = navigationView.getMenu().findItem(R.id.action_mode_favs);
navItem = _navigationView.getMenu().findItem(R.id.action_mode_favs);
break;
case 2:
navItem = navigationView.getMenu().findItem(R.id.action_mode_saved);
navItem = _navigationView.getMenu().findItem(R.id.action_mode_saved);
break;
}

if (navItem != null) {
navigationView.setCheckedItem(navItem.getItemId());
_navigationView.setCheckedItem(navItem.getItemId());
onNavigationItemSelected(navItem);
}
}

@Override
protected void onResume() {
if (isShowingFullscreenImage) {
isShowingFullscreenImage = false;
if (_isShowingFullscreenImage) {
_isShowingFullscreenImage = false;
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
}

Expand Down Expand Up @@ -209,8 +217,8 @@ protected void onResume() {

@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
if (_drawer.isDrawerOpen(GravityCompat.START)) {
_drawer.closeDrawer(GravityCompat.START);
return;
}
super.onBackPressed();
Expand Down Expand Up @@ -260,45 +268,45 @@ public boolean handleBarClick(MenuItem item) {
}

case R.id.action_mode_create: {
emptylistText.setText(getString(R.string.main__nodata__custom_templates, getString(R.string.custom_templates_visual)));
_emptylistText.setText(getString(R.string.main__nodata__custom_templates, getString(R.string.custom_templates_visual)));
selectTab(app.settings.getLastSelectedTab(), app.settings.getDefaultMainMode());
toolbar.setTitle(R.string.app_name);
_toolbar.setTitle(R.string.app_name);
break;
}
case R.id.action_mode_favs: {
emptylistText.setText(R.string.main__nodata__favourites);
_emptylistText.setText(R.string.main__nodata__favourites);
memeOriginObject = new MemeOriginFavorite(app.settings.getFavoriteMemes(), getAssets());
toolbar.setTitle(R.string.main__mode__favs);
_toolbar.setTitle(R.string.main__mode__favs);
break;
}
case R.id.action_mode_saved: {
emptylistText.setText(R.string.main__nodata__saved);
_emptylistText.setText(R.string.main__nodata__saved);
File filePath = ContextUtils.get().getPicturesMemetasticFolder();
filePath.mkdirs();
memeOriginObject = new MemeOriginStorage(filePath, getString(R.string.dot_thumbnails));
toolbar.setTitle(R.string.main__mode__saved);
_toolbar.setTitle(R.string.main__mode__saved);
break;
}
}

// Change mode
tabLayout.setVisibility(item.getItemId() == R.id.action_mode_create ? View.VISIBLE : View.GONE);
_tabLayout.setVisibility(item.getItemId() == R.id.action_mode_create ? View.VISIBLE : View.GONE);
if (memeOriginObject != null) {
drawer.closeDrawers();
_drawer.closeDrawers();
GridRecycleAdapter recyclerMemeAdapter = new GridRecycleAdapter(memeOriginObject, this);
setRecyclerMemeListAdapter(recyclerMemeAdapter);
return true;
}

drawer.closeDrawer(GravityCompat.START);
_drawer.closeDrawer(GravityCompat.START);
return true;
}

private void setRecyclerMemeListAdapter(RecyclerView.Adapter adapter) {
recyclerMemeList.setAdapter(adapter);
_recyclerMemeList.setAdapter(adapter);
boolean isEmpty = adapter.getItemCount() == 0;
emptylistLayout.setVisibility(isEmpty ? View.VISIBLE : View.GONE);
recyclerMemeList.setVisibility(isEmpty ? View.GONE : View.VISIBLE);
_emptylistLayout.setVisibility(isEmpty ? View.VISIBLE : View.GONE);
_recyclerMemeList.setVisibility(isEmpty ? View.GONE : View.VISIBLE);
}

@Override
Expand Down Expand Up @@ -378,7 +386,7 @@ public void onImageTemplateWasChosen(String filePath, boolean bIsAsset) {
}

public void openImageViewActivityWithImage(String imagePath) {
isShowingFullscreenImage = true;
_isShowingFullscreenImage = true;

Intent intent = new Intent(this, ImageViewActivity.class);
intent.putExtra(IMAGE_PATH, imagePath);
Expand All @@ -400,12 +408,12 @@ public void onTabSelected(TabLayout.Tab tab) {
// Custom tab
if (tabPos >= 0 && tabPos == MemeLibConfig.MEME_CATEGORIES.ALL.length) {
File customFolder = ContextUtils.get().getPicturesMemetasticTemplatesCustomFolder();
emptylistText.setText(getString(R.string.main__nodata__custom_templates, getString(R.string.custom_templates_visual)));
_emptylistText.setText(getString(R.string.main__nodata__custom_templates, getString(R.string.custom_templates_visual)));
memeOriginObject = new MemeOriginStorage(customFolder, getString(R.string.dot_thumbnails));
((MemeOriginStorage) memeOriginObject).setIsTemplate(true);
}
if (memeOriginObject != null) {
if (areTabsReady) {
if (_areTabsReady) {
app.settings.setLastSelectedTab(tabPos);
}
if (app.settings.isShuffleMemeCategories()) {
Expand All @@ -423,14 +431,14 @@ public void onTabSelected(TabLayout.Tab tab) {

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (!drawer.isDrawerOpen(GravityCompat.START) && !drawer.isDrawerVisible(GravityCompat.START) && tabLayout.getVisibility() == View.VISIBLE) {
if (event.getAction() == MotionEvent.ACTION_DOWN && event.getY() > (tabLayout.getY() * 2.2)) {
if (!_drawer.isDrawerOpen(GravityCompat.START) && !_drawer.isDrawerVisible(GravityCompat.START) && _tabLayout.getVisibility() == View.VISIBLE) {
if (event.getAction() == MotionEvent.ACTION_DOWN && event.getY() > (_tabLayout.getY() * 2.2)) {
point.set(event.getX(), event.getY(), 0, 0);
} else if (event.getAction() == MotionEvent.ACTION_UP) {
point.set(point.left, point.top, event.getX(), event.getY());
if (Math.abs(point.width()) > SWIPE_MIN_DX && Math.abs(point.height()) < SWIPE_MAX_DY) {
// R->L : L<-R
selectTab(tabLayout.getSelectedTabPosition() + (point.width() > 0 ? -1 : +1), 0);
selectTab(_tabLayout.getSelectedTabPosition() + (point.width() > 0 ? -1 : +1), 0);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected void onCreate(Bundle savedInstanceState) {
ButterKnife.bind(this);
app = (App) getApplication();

// Set toolbar
// Set _toolbar
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/progressbar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="@color/white" />
</shape>
</clip>
</item>
</layer-list>
63 changes: 63 additions & 0 deletions app/src/main/res/layout/main__content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,69 @@
android:id="@+id/main__activity__recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/main__activity__infobar"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scrollbars="vertical" />


<LinearLayout
android:id="@+id/main__activity__infobar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:background="@color/snackbar"
android:orientation="vertical"
android:visibility="gone">

<ProgressBar
android:id="@+id/main__activity__infobar__progress"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="7dp"
android:indeterminate="false"
android:progressDrawable="@drawable/progressbar" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:id="@+id/main__activity__infobar__image"
android:layout_width="32dp"
android:layout_height="match_parent"
android:layout_marginEnd="6dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginStart="6dp"
android:src="@drawable/ic_launcher" />

<TextView
android:id="@+id/main__activity__infobar__text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|start"
android:layout_marginEnd="6dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginStart="6dp"
android:paddingBottom="14dp"
android:paddingTop="14dp"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.Design.Snackbar.Message"
android:theme="@style/ThemeOverlay.AppCompat.Dark" />

</LinearLayout>

</LinearLayout>


</RelativeLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<color name="empty_list_background_text">#757575</color>


<color name="snackbar">#353535</color>
<color name="black">#000</color>
<color name="white">#ffffff</color>

Expand Down

0 comments on commit 629d214

Please sign in to comment.