aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-11 14:29:00 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-11 14:29:00 +0000
commit002fa44d8a8e640dfe6643f65b266b552be029cb (patch)
treee4aa3295704ef0ba7ea25632265a0f30d7b16200 /app/src/main
parent2913c1583b8001ebdf75babb2d663f3cf9167ca9 (diff)
downloadinfinity-for-reddit-002fa44d8a8e640dfe6643f65b266b552be029cb.tar
infinity-for-reddit-002fa44d8a8e640dfe6643f65b266b552be029cb.tar.gz
infinity-for-reddit-002fa44d8a8e640dfe6643f65b266b552be029cb.tar.bz2
infinity-for-reddit-002fa44d8a8e640dfe6643f65b266b552be029cb.tar.lz
infinity-for-reddit-002fa44d8a8e640dfe6643f65b266b552be029cb.tar.xz
infinity-for-reddit-002fa44d8a8e640dfe6643f65b266b552be029cb.tar.zst
infinity-for-reddit-002fa44d8a8e640dfe6643f65b266b552be029cb.zip
Showing a toast instead of a snackbar when the window flag is set to FLAG_LAYOUT_NO_LIMITS to prevent the snackbar being shown behind the nav bar.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java51
3 files changed, 51 insertions, 26 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index ae0ee53b..e3bf8ee8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -86,6 +86,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
@State
boolean hasMoreChildren;
+ private boolean showToast = false;
+
private LinearLayoutManager mLinearLayoutManager;
private CommentAndPostRecyclerViewAdapter mAdapter;
private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask;
@@ -151,6 +153,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
int navBarResourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (navBarResourceId > 0) {
mRecyclerView.setPadding(0, 0, 0, resources.getDimensionPixelSize(navBarResourceId));
+
+ showToast = true;
}
}
@@ -420,7 +424,11 @@ public class ViewPostDetailActivity extends AppCompatActivity {
@Override
public void fetchPostFailed() {
- Snackbar.make(mCoordinatorLayout, R.string.refresh_post_failed, Snackbar.LENGTH_SHORT);
+ if(showToast) {
+ Toast.makeText(ViewPostDetailActivity.this, R.string.refresh_post_failed, Toast.LENGTH_SHORT).show();
+ } else {
+ Snackbar.make(mCoordinatorLayout, R.string.refresh_post_failed, Snackbar.LENGTH_SHORT);
+ }
isRefreshing = false;
}
});
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
index efbc07a1..f398fbe6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
@@ -13,6 +13,7 @@ import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
@@ -74,6 +75,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
private boolean mFetchSubredditInfoSuccess = false;
private boolean subscriptionReady = false;
private boolean isInLazyMode = false;
+ private boolean showToast = false;
private RequestManager glide;
private Fragment mFragment;
@@ -135,6 +137,8 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams();
params.bottomMargin = resources.getDimensionPixelSize(navBarResourceId);
fab.setLayoutParams(params);
+
+ showToast = true;
}
}
}
@@ -427,11 +431,15 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
}
private void makeSnackbar(int resId, boolean retry) {
- if(retry) {
- Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).setAction(R.string.retry,
- view -> fetchSubredditData()).show();
+ if(showToast) {
+ Toast.makeText(this, resId, Toast.LENGTH_SHORT).show();
} else {
- Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).show();
+ if(retry) {
+ Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).setAction(R.string.retry,
+ view -> fetchSubredditData()).show();
+ } else {
+ Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).show();
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
index f88b5ac8..61e4f5cb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java
@@ -13,6 +13,7 @@ import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
@@ -98,6 +99,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
private int collapsedTabTextColor;
private int collapsedTabBackgroundColor;
private int collapsedTabIndicatorColor;
+ private boolean showToast = false;
@Inject
@Named("no_oauth")
@@ -141,11 +143,13 @@ public class ViewUserDetailActivity extends AppCompatActivity {
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
+ Resources resources = getResources();
+
//Get status bar height
int statusBarHeight = 0;
- int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
+ int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
- statusBarHeight = getResources().getDimensionPixelSize(resourceId);
+ statusBarHeight = resources.getDimensionPixelSize(resourceId);
}
String title = "u/" + username;
@@ -158,15 +162,13 @@ public class ViewUserDetailActivity extends AppCompatActivity {
ViewGroup.MarginLayoutParams toolbarLayoutParams = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
toolbarLayoutParams.topMargin = statusBarHeight;
- expandedTabTextColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTextColor);
- expandedTabBackgroundColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabBackground);
- expandedTabIndicatorColor = getResources().getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabIndicator);
+ expandedTabTextColor = resources.getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTextColor);
+ expandedTabBackgroundColor = resources.getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabBackground);
+ expandedTabIndicatorColor = resources.getColor(R.color.tabLayoutWithExpandedCollapsingToolbarTabIndicator);
- collapsedTabTextColor = getResources().getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTextColor);
- collapsedTabBackgroundColor = getResources().getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabBackground);
- collapsedTabIndicatorColor = getResources().getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabIndicator);
-
- Resources resources = getResources();
+ collapsedTabTextColor = resources.getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTextColor);
+ collapsedTabBackgroundColor = resources.getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabBackground);
+ collapsedTabIndicatorColor = resources.getColor(R.color.tabLayoutWithCollapsedCollapsingToolbarTabIndicator);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1
&& (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
@@ -192,11 +194,14 @@ public class ViewUserDetailActivity extends AppCompatActivity {
}
});
- int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
+ int statusBarResourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
if (statusBarResourceId > 0) {
+ int navBarHeight = resources.getDimensionPixelSize(statusBarResourceId);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
- params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId);
+ params.topMargin = navBarHeight;
toolbar.setLayoutParams(params);
+
+ showToast = true;
}
} else {
appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
@@ -265,13 +270,13 @@ public class ViewUserDetailActivity extends AppCompatActivity {
subscribeUserChip.setOnClickListener(view -> {
if (subscriptionReady) {
subscriptionReady = false;
- if (subscribeUserChip.getText().equals(getResources().getString(R.string.follow))) {
+ if (subscribeUserChip.getText().equals(resources.getString(R.string.follow))) {
UserFollowing.followUser(mOauthRetrofit, mRetrofit, mAccessToken,
username, mAccountName, subscribedUserDao, new UserFollowing.UserFollowingListener() {
@Override
public void onUserFollowingSuccess() {
subscribeUserChip.setText(R.string.unfollow);
- subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorAccent));
+ subscribeUserChip.setChipBackgroundColor(resources.getColorStateList(R.color.colorAccent));
makeSnackbar(R.string.followed, false);
subscriptionReady = true;
}
@@ -288,7 +293,7 @@ public class ViewUserDetailActivity extends AppCompatActivity {
@Override
public void onUserFollowingSuccess() {
subscribeUserChip.setText(R.string.follow);
- subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.backgroundColorPrimaryDark));
+ subscribeUserChip.setChipBackgroundColor(resources.getColorStateList(R.color.backgroundColorPrimaryDark));
makeSnackbar(R.string.unfollowed, false);
subscriptionReady = true;
}
@@ -307,14 +312,14 @@ public class ViewUserDetailActivity extends AppCompatActivity {
@Override
public void isSubscribed() {
subscribeUserChip.setText(R.string.unfollow);
- subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorAccent));
+ subscribeUserChip.setChipBackgroundColor(resources.getColorStateList(R.color.colorAccent));
subscriptionReady = true;
}
@Override
public void isNotSubscribed() {
subscribeUserChip.setText(R.string.follow);
- subscribeUserChip.setChipBackgroundColor(getResources().getColorStateList(R.color.backgroundColorPrimaryDark));
+ subscribeUserChip.setChipBackgroundColor(resources.getColorStateList(R.color.backgroundColorPrimaryDark));
subscriptionReady = true;
}
}).execute();
@@ -438,11 +443,15 @@ public class ViewUserDetailActivity extends AppCompatActivity {
}
private void makeSnackbar(int resId, boolean retry) {
- if (retry) {
- Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).setAction(R.string.retry,
- view -> fetchUserInfo()).show();
+ if(showToast) {
+ Toast.makeText(this, resId, Toast.LENGTH_SHORT).show();
} else {
- Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).show();
+ if (retry) {
+ Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).setAction(R.string.retry,
+ view -> fetchUserInfo()).show();
+ } else {
+ Snackbar.make(coordinatorLayout, resId, Snackbar.LENGTH_SHORT).show();
+ }
}
}