aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-09-27 09:06:55 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-09-27 09:06:55 +0000
commitca19c566c338a8c815ce68aa88e3a09987112881 (patch)
tree25d9036af4de32a738251bc1a476685394ec7e89 /app/src/main/java/ml/docilealligator/infinityforreddit
parent62a457a868a5441483cbce8de7ec43db106d880d (diff)
downloadinfinity-for-reddit-ca19c566c338a8c815ce68aa88e3a09987112881.tar
infinity-for-reddit-ca19c566c338a8c815ce68aa88e3a09987112881.tar.gz
infinity-for-reddit-ca19c566c338a8c815ce68aa88e3a09987112881.tar.bz2
infinity-for-reddit-ca19c566c338a8c815ce68aa88e3a09987112881.tar.lz
infinity-for-reddit-ca19c566c338a8c815ce68aa88e3a09987112881.tar.xz
infinity-for-reddit-ca19c566c338a8c815ce68aa88e3a09987112881.tar.zst
infinity-for-reddit-ca19c566c338a8c815ce68aa88e3a09987112881.zip
Long press the Floating Action Button to see more options.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java39
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java43
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/FABMoreOptionsBottomSheetFragment.java87
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/PostTypeBottomSheetFragment.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java4
5 files changed, 160 insertions, 14 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
index 66689f59..c98a5e84 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
@@ -67,6 +67,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchToAnonymousAccountAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.FABMoreOptionsBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTimeBottomSheetFragment;
@@ -104,7 +105,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
public class MainActivity extends BaseActivity implements SortTypeSelectionCallback,
PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback,
- ActivityToolbarInterface {
+ ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback {
static final String EXTRA_POST_TYPE = "EPT";
static final String EXTRA_MESSSAGE_FULLNAME = "ENF";
@@ -191,6 +192,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
+ private FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment;
private NavigationDrawerRecyclerViewAdapter adapter;
private boolean mNullAccessToken = false;
private String mAccessToken;
@@ -264,6 +266,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
+ fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment();
setSupportActionBar(toolbar);
setToolbarGoToTop(toolbar);
@@ -555,13 +558,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
int fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS);
switch (fabOption) {
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_REFRESH:
- fab.setImageResource(R.drawable.ic_refresh_black_24dp);
+ fab.setImageResource(R.drawable.ic_refresh_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE:
- fab.setImageResource(R.drawable.ic_sort_toolbar_24dp);
+ fab.setImageResource(R.drawable.ic_sort_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT:
- fab.setImageResource(R.drawable.ic_post_layout_black_24dp);
+ fab.setImageResource(R.drawable.ic_post_layout_24dp);
break;
case SharedPreferencesUtils.MAIN_ACTIVITY_BOTTOM_APP_BAR_FAB_SEARCH:
fab.setImageResource(R.drawable.ic_search_black_24dp);
@@ -596,6 +599,10 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
break;
}
});
+ fab.setOnLongClickListener(view -> {
+ fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag());
+ return true;
+ });
fab.setVisibility(View.VISIBLE);
}
@@ -1130,6 +1137,30 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
}
+ @Override
+ public void fabOptionSelected(int option) {
+ switch (option) {
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SUBMIT_POST:
+ postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
+ break;
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_REFRESH:
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.refresh();
+ }
+ break;
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE:
+ changeSortType();
+ break;
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_POST_LAYOUT:
+ postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
+ break;
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH:
+ Intent intent = new Intent(this, SearchActivity.class);
+ startActivity(intent);
+ break;
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentStateAdapter {
int tabCount;
boolean showFavoriteSubscribedSubreddits;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
index 79c881fd..f1799f06 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -60,6 +60,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsSubscribedToSubredd
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
+import ml.docilealligator.infinityforreddit.BottomSheetFragment.FABMoreOptionsBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.PostTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.SortTimeBottomSheetFragment;
@@ -89,7 +90,7 @@ import retrofit2.Retrofit;
public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback,
- ActivityToolbarInterface {
+ ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback {
public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN";
public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
@@ -196,6 +197,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
+ private FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment;
private int expandedTabTextColor;
private int expandedTabBackgroundColor;
private int expandedTabIndicatorColor;
@@ -341,8 +343,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
sortTypeBottomSheetFragment.setArguments(bottomSheetBundle);
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
-
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
+ fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment();
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@@ -643,13 +645,13 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
int fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS);
switch (fabOption) {
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH:
- fab.setImageResource(R.drawable.ic_refresh_black_24dp);
+ fab.setImageResource(R.drawable.ic_refresh_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE:
- fab.setImageResource(R.drawable.ic_sort_toolbar_24dp);
+ fab.setImageResource(R.drawable.ic_sort_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT:
- fab.setImageResource(R.drawable.ic_post_layout_black_24dp);
+ fab.setImageResource(R.drawable.ic_post_layout_24dp);
break;
case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH:
fab.setImageResource(R.drawable.ic_search_black_24dp);
@@ -685,6 +687,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
break;
}
});
+ fab.setOnLongClickListener(view -> {
+ fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag());
+ return true;
+ });
fab.setVisibility(View.VISIBLE);
} else {
@@ -1017,9 +1023,32 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
}
+ @Override
+ public void fabOptionSelected(int option) {
+ switch (option) {
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SUBMIT_POST:
+ postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag());
+ break;
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_REFRESH:
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.refresh();
+ }
+ break;
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE:
+ sortTypeBottomSheetFragment.show(getSupportFragmentManager(), sortTypeBottomSheetFragment.getTag());
+ break;
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_POST_LAYOUT:
+ postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
+ break;
+ case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH:
+ Intent intent = new Intent(this, SearchActivity.class);
+ intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ break;
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentStateAdapter {
- /*private PostFragment postFragment;
- private SidebarFragment sidebarFragment;*/
SectionsPagerAdapter(FragmentManager fm, Lifecycle lifecycle) {
super(fm, lifecycle);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/FABMoreOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/FABMoreOptionsBottomSheetFragment.java
new file mode 100644
index 00000000..dc4b212b
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/FABMoreOptionsBottomSheetFragment.java
@@ -0,0 +1,87 @@
+package ml.docilealligator.infinityforreddit.BottomSheetFragment;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+
+import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.R;
+
+public class FABMoreOptionsBottomSheetFragment extends RoundedBottomSheetDialogFragment {
+
+ public static final int FAB_OPTION_SUBMIT_POST = 0;
+ public static final int FAB_OPTION_REFRESH = 1;
+ public static final int FAB_OPTION_CHANGE_SORT_TYPE = 2;
+ public static final int FAB_OPTION_CHANGE_POST_LAYOUT = 3;
+ public static final int FAB_OPTION_SEARCH = 4;
+
+ @BindView(R.id.submit_post_text_view_fab_more_options_bottom_sheet_fragment)
+ TextView submitPostTextView;
+ @BindView(R.id.refresh_text_view_fab_more_options_bottom_sheet_fragment)
+ TextView refreshTextView;
+ @BindView(R.id.change_sort_type_text_view_fab_more_options_bottom_sheet_fragment)
+ TextView changeSortTypeTextView;
+ @BindView(R.id.change_post_layout_text_view_fab_more_options_bottom_sheet_fragment)
+ TextView changePostLayoutTextView;
+ @BindView(R.id.search_text_view_fab_more_options_bottom_sheet_fragment)
+ TextView searchTextView;
+ private FABOptionSelectionCallback activity;
+
+ public FABMoreOptionsBottomSheetFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ View rootView = inflater.inflate(R.layout.fragment_fab_more_options_bottom_sheet, container, false);
+
+ ButterKnife.bind(this, rootView);
+
+ submitPostTextView.setOnClickListener(view -> {
+ activity.fabOptionSelected(FAB_OPTION_SUBMIT_POST);
+ dismiss();
+ });
+
+ refreshTextView.setOnClickListener(view -> {
+ activity.fabOptionSelected(FAB_OPTION_REFRESH);
+ dismiss();
+ });
+
+ changeSortTypeTextView.setOnClickListener(view -> {
+ activity.fabOptionSelected(FAB_OPTION_CHANGE_SORT_TYPE);
+ dismiss();
+ });
+
+ changePostLayoutTextView.setOnClickListener(view -> {
+ activity.fabOptionSelected(FAB_OPTION_CHANGE_POST_LAYOUT);
+ dismiss();
+ });
+
+ searchTextView.setOnClickListener(view -> {
+ activity.fabOptionSelected(FAB_OPTION_SEARCH);
+ dismiss();
+ });
+
+ return rootView;
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ this.activity = (FABOptionSelectionCallback) context;
+ }
+
+ public interface FABOptionSelectionCallback {
+ void fabOptionSelected(int option);
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/PostTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/PostTypeBottomSheetFragment.java
index 1f40fc22..328aeec2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/PostTypeBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/BottomSheetFragment/PostTypeBottomSheetFragment.java
@@ -39,6 +39,7 @@ public class PostTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
@BindView(R.id.video_type_linear_layout_post_type_bottom_sheet_fragment)
TextView videoTypeTextView;
private Activity activity;
+
public PostTypeBottomSheetFragment() {
// Required empty public constructor
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
index d9ee278c..4ee21747 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Infinity.java
@@ -46,9 +46,7 @@ public class Infinity extends Application {
EventBus.builder().addIndex(new EventBusIndex()).installDefaultEventBus();
mNetworkWifiStatusReceiver =
- new NetworkWifiStatusReceiver(() -> {
- EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext())));
- });
+ new NetworkWifiStatusReceiver(() -> EventBus.getDefault().post(new ChangeNetworkStatusEvent(Utils.getConnectedNetwork(getApplicationContext()))));
registerReceiver(mNetworkWifiStatusReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}