aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-07-26 15:31:48 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-07-26 15:31:48 +0000
commit40fc423b337352e1a47e361dac052213bb81ee26 (patch)
treec79667c0b51f15046661dacbcdf0d018178b1854 /app/src/main/java/ml
parent1fc84239069fa19da7f7c7b0b0825717aad4999c (diff)
downloadinfinity-for-reddit-40fc423b337352e1a47e361dac052213bb81ee26.tar
infinity-for-reddit-40fc423b337352e1a47e361dac052213bb81ee26.tar.gz
infinity-for-reddit-40fc423b337352e1a47e361dac052213bb81ee26.tar.bz2
infinity-for-reddit-40fc423b337352e1a47e361dac052213bb81ee26.tar.lz
infinity-for-reddit-40fc423b337352e1a47e361dac052213bb81ee26.tar.xz
infinity-for-reddit-40fc423b337352e1a47e361dac052213bb81ee26.tar.zst
infinity-for-reddit-40fc423b337352e1a47e361dac052213bb81ee26.zip
Use rounded corner bottom fragment. Tweak bottom sheet fragment UI. Change post type bottom sheet dialog to fragment. Exit SearchActivity no matter searchview is open or not.
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java66
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostTypeBottomSheetFragment.java74
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeBottomSheetFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java75
5 files changed, 135 insertions, 92 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
index efb651a4..08dba87e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java
@@ -25,7 +25,6 @@ import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
-import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import javax.inject.Inject;
@@ -37,7 +36,8 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
-public class MainActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback {
+public class MainActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
+ PostTypeBottomSheetFragment.PostTypeSelectionCallback {
private static final String FRAGMENT_OUT_STATE = "FOS";
private static final String FETCH_USER_INFO_STATE = "FUIS";
@@ -60,7 +60,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
private Fragment mFragment;
private RequestManager glide;
private AppBarLayout.LayoutParams params;
- private BottomSheetDialog postTypedialog;
+ private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private String mName;
@@ -94,15 +94,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
((Infinity) getApplication()).getmAppComponent().inject(this);
- View postTypeDialogView = View.inflate(this, R.layout.post_type_bottom_sheet, null);
- LinearLayout textTypeLinearLayout = postTypeDialogView.findViewById(R.id.text_type_linear_layout_post_type_bottom_sheet);
- LinearLayout linkTypeLinearLayout = postTypeDialogView.findViewById(R.id.link_type_linear_layout_post_type_bottom_sheet);
- LinearLayout imageTypeLinearLayout = postTypeDialogView.findViewById(R.id.image_type_linear_layout_post_type_bottom_sheet);
- LinearLayout videoTypeLinearLayout = postTypeDialogView.findViewById(R.id.video_type_linear_layout_post_type_bottom_sheet);
-
- postTypedialog = new BottomSheetDialog(this);
- postTypedialog.setContentView(postTypeDialogView);
-
+ postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
Toolbar toolbar = findViewById(R.id.toolbar);
@@ -181,31 +173,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
});
}
- textTypeLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(MainActivity.this, PostTextActivity.class);
- startActivity(intent);
- postTypedialog.dismiss();
- });
-
- linkTypeLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(MainActivity.this, PostLinkActivity.class);
- startActivity(intent);
- postTypedialog.dismiss();
- });
-
- imageTypeLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(MainActivity.this, PostImageActivity.class);
- startActivity(intent);
- postTypedialog.dismiss();
- });
-
- videoTypeLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(MainActivity.this, PostVideoActivity.class);
- startActivity(intent);
- postTypedialog.dismiss();
- });
-
- fab.setOnClickListener(view -> postTypedialog.show());
+ fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
}
private void replaceFragment(String sortType) {
@@ -303,7 +271,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
}
@Override
- public boolean onOptionsItemSelected(MenuItem item) {
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (mFragment instanceof FragmentCommunicator) {
switch (item.getItemId()) {
case R.id.action_sort_main_activity:
@@ -364,4 +332,26 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
public void sortTypeSelected(String sortType) {
replaceFragment(sortType);
}
+
+ @Override
+ public void postTypeSelected(int postType) {
+ Intent intent;
+ switch (postType) {
+ case PostTypeBottomSheetFragment.TYPE_TEXT:
+ intent = new Intent(MainActivity.this, PostTextActivity.class);
+ startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_LINK:
+ intent = new Intent(MainActivity.this, PostLinkActivity.class);
+ startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_IMAGE:
+ intent = new Intent(MainActivity.this, PostImageActivity.class);
+ startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_VIDEO:
+ intent = new Intent(MainActivity.this, PostVideoActivity.class);
+ startActivity(intent);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTypeBottomSheetFragment.java
new file mode 100644
index 00000000..c8dd0d28
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTypeBottomSheetFragment.java
@@ -0,0 +1,74 @@
+package ml.docilealligator.infinityforreddit;
+
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+import androidx.fragment.app.Fragment;
+
+import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class PostTypeBottomSheetFragment extends RoundedBottomSheetDialogFragment {
+
+ interface PostTypeSelectionCallback {
+ void postTypeSelected(int postType);
+ }
+
+ static final int TYPE_TEXT = 0;
+ static final int TYPE_LINK = 1;
+ static final int TYPE_IMAGE = 2;
+ static final int TYPE_VIDEO = 3;
+
+ @BindView(R.id.text_type_linear_layout_post_type_bottom_sheet_fragment) LinearLayout textTypeLinearLayout;
+ @BindView(R.id.link_type_linear_layout_post_type_bottom_sheet_fragment) LinearLayout linkTypeLinearLayout;
+ @BindView(R.id.image_type_linear_layout_post_type_bottom_sheet_fragment) LinearLayout imageTypeLinearLayout;
+ @BindView(R.id.video_type_linear_layout_post_type_bottom_sheet_fragment) LinearLayout videoTypeLinearLayout;
+
+ public PostTypeBottomSheetFragment() {
+ // Required empty public constructor
+ }
+
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View rootView = inflater.inflate(R.layout.fragment_post_type_bottom_sheet, container, false);
+ ButterKnife.bind(this, rootView);
+
+ Activity activity = getActivity();
+
+ textTypeLinearLayout.setOnClickListener(view -> {
+ ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_TEXT);
+ dismiss();
+ });
+
+ linkTypeLinearLayout.setOnClickListener(view -> {
+ ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_LINK);
+ dismiss();
+ });
+
+ imageTypeLinearLayout.setOnClickListener(view -> {
+ ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_IMAGE);
+ dismiss();
+ });
+
+ videoTypeLinearLayout.setOnClickListener(view -> {
+ ((PostTypeSelectionCallback) activity).postTypeSelected(TYPE_VIDEO);
+ dismiss();
+ });
+
+ return rootView;
+ }
+
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
index 725b50a0..cd828c80 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchActivity.java
@@ -147,14 +147,6 @@ public class SearchActivity extends AppCompatActivity {
}
@Override
- public void onBackPressed() {
- if (simpleSearchView.onBackPressed()) {
- return;
- }
- super.onBackPressed();
- }
-
- @Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeBottomSheetFragment.java
index 1af128a0..8e25c271 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SortTypeBottomSheetFragment.java
@@ -11,7 +11,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
-import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
+import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -20,7 +20,7 @@ import butterknife.ButterKnife;
/**
* A simple {@link Fragment} subclass.
*/
-public class SortTypeBottomSheetFragment extends BottomSheetDialogFragment {
+public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragment {
interface SortTypeSelectionCallback {
void sortTypeSelected(String sortType);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
index e6ff9bfe..9996a4af 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewSubredditDetailActivity.java
@@ -8,7 +8,6 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
-import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
@@ -23,7 +22,6 @@ import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
-import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.chip.Chip;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
@@ -43,7 +41,8 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
-public class ViewSubredditDetailActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback {
+public class ViewSubredditDetailActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
+ PostTypeBottomSheetFragment.PostTypeSelectionCallback {
public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN";
@@ -71,7 +70,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
private Fragment mFragment;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
- private BottomSheetDialog dialog;
+ private PostTypeBottomSheetFragment postTypeBottomSheetFragment;
private SortTypeBottomSheetFragment sortTypeBottomSheetFragment;
private SubscribedSubredditDao subscribedSubredditDao;
@@ -98,15 +97,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
((Infinity) getApplication()).getmAppComponent().inject(this);
- View dialogView = View.inflate(this, R.layout.post_type_bottom_sheet, null);
- LinearLayout textTypeLinearLayout = dialogView.findViewById(R.id.text_type_linear_layout_post_type_bottom_sheet);
- LinearLayout linkTypeLinearLayout = dialogView.findViewById(R.id.link_type_linear_layout_post_type_bottom_sheet);
- LinearLayout imageTypeLinearLayout = dialogView.findViewById(R.id.image_type_linear_layout_post_type_bottom_sheet);
- LinearLayout videoTypeLinearLayout = dialogView.findViewById(R.id.video_type_linear_layout_post_type_bottom_sheet);
-
- dialog = new BottomSheetDialog(this);
- dialog.setContentView(dialogView);
-
+ postTypeBottomSheetFragment = new PostTypeBottomSheetFragment();
sortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@@ -277,37 +268,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
}
- textTypeLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(this, PostTextActivity.class);
- intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, subredditName);
- startActivity(intent);
- dialog.dismiss();
- });
-
- linkTypeLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(this, PostLinkActivity.class);
- intent.putExtra(PostLinkActivity.EXTRA_SUBREDDIT_NAME, subredditName);
- startActivity(intent);
- dialog.dismiss();
- });
-
- imageTypeLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(this, PostImageActivity.class);
- intent.putExtra(PostImageActivity.EXTRA_SUBREDDIT_NAME, subredditName);
- startActivity(intent);
- dialog.dismiss();
- });
-
- videoTypeLinearLayout.setOnClickListener(view -> {
- Intent intent = new Intent(this, PostVideoActivity.class);
- intent.putExtra(PostVideoActivity.EXTRA_SUBREDDIT_NAME, subredditName);
- startActivity(intent);
- dialog.dismiss();
- });
-
- fab.setOnClickListener(view -> {
- dialog.show();
- });
+ fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
}
@Override
@@ -395,6 +356,32 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
replaceFragment(sortType);
}
+ @Override
+ public void postTypeSelected(int postType) {
+ Intent intent;
+ switch (postType) {
+ case PostTypeBottomSheetFragment.TYPE_TEXT:
+ intent = new Intent(this, PostTextActivity.class);
+ intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_LINK:
+ intent = new Intent(this, PostLinkActivity.class);
+ intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_IMAGE:
+ intent = new Intent(this, PostImageActivity.class);
+ intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ break;
+ case PostTypeBottomSheetFragment.TYPE_VIDEO:
+ intent = new Intent(this, PostVideoActivity.class);
+ intent.putExtra(PostTextActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ }
+ }
+
private static class InsertSubredditDataAsyncTask extends AsyncTask<Void, Void, Void> {
private SubredditDao mSubredditDao;