From 40fc423b337352e1a47e361dac052213bb81ee26 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 26 Jul 2019 23:31:48 +0800 Subject: 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. --- .idea/caches/build_file_checksums.ser | Bin 533 -> 533 bytes .idea/caches/gradle_models.ser | Bin 254866 -> 257686 bytes app/build.gradle | 1 + .../infinityforreddit/MainActivity.java | 66 +++++------ .../PostTypeBottomSheetFragment.java | 74 ++++++++++++ .../infinityforreddit/SearchActivity.java | 8 -- .../SortTypeBottomSheetFragment.java | 4 +- .../ViewSubredditDetailActivity.java | 75 +++++------- .../res/layout/fragment_post_type_bottom_sheet.xml | 130 +++++++++++++++++++++ .../res/layout/fragment_sort_type_bottom_sheet.xml | 60 ++++++---- app/src/main/res/layout/post_type_bottom_sheet.xml | 122 ------------------- app/src/main/res/layout/sort_type_bottom_sheet.xml | 97 --------------- app/src/main/res/values/colors.xml | 2 + app/src/main/res/values/dimens.xml | 3 + 14 files changed, 307 insertions(+), 335 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/PostTypeBottomSheetFragment.java create mode 100644 app/src/main/res/layout/fragment_post_type_bottom_sheet.xml delete mode 100644 app/src/main/res/layout/post_type_bottom_sheet.xml delete mode 100644 app/src/main/res/layout/sort_type_bottom_sheet.xml diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 4b5c0b5d..94e2cf6f 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser index 80643aa1..058c966f 100644 Binary files a/.idea/caches/gradle_models.ser and b/.idea/caches/gradle_models.ser differ diff --git a/app/build.gradle b/app/build.gradle index 92fb64ab..83263b79 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -75,4 +75,5 @@ dependencies { implementation 'com.github.Ferfalk:SimpleSearchView:0.1.3' implementation 'org.greenrobot:eventbus:3.1.1' implementation 'com.libRG:customtextview:2.2' + implementation 'com.github.Deishelon:RoundedBottomSheet:1.0.1' } 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 @@ -146,14 +146,6 @@ public class SearchActivity extends AppCompatActivity { return false; } - @Override - public void onBackPressed() { - if (simpleSearchView.onBackPressed()) { - return; - } - super.onBackPressed(); - } - @Override public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); 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 { private SubredditDao mSubredditDao; diff --git a/app/src/main/res/layout/fragment_post_type_bottom_sheet.xml b/app/src/main/res/layout/fragment_post_type_bottom_sheet.xml new file mode 100644 index 00000000..1e3659d1 --- /dev/null +++ b/app/src/main/res/layout/fragment_post_type_bottom_sheet.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_sort_type_bottom_sheet.xml b/app/src/main/res/layout/fragment_sort_type_bottom_sheet.xml index bdf38858..d3977d81 100644 --- a/app/src/main/res/layout/fragment_sort_type_bottom_sheet.xml +++ b/app/src/main/res/layout/fragment_sort_type_bottom_sheet.xml @@ -1,13 +1,18 @@ + android:layout_height="match_parent" + android:paddingBottom="8dp"> @@ -27,9 +33,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/sort_hot" - android:textColor="@color/primaryTextColor" - android:textSize="18sp" - android:padding="16dp" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" android:clickable="true" android:focusable="true" android:background="?attr/selectableItemBackground" /> @@ -39,9 +46,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/sort_new" - android:textColor="@color/primaryTextColor" - android:textSize="18sp" - android:padding="16dp" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" android:clickable="true" android:focusable="true" android:background="?attr/selectableItemBackground" /> @@ -51,9 +59,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/sort_random" - android:textColor="@color/primaryTextColor" - android:textSize="18sp" - android:padding="16dp" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" android:clickable="true" android:focusable="true" android:background="?attr/selectableItemBackground" /> @@ -63,9 +72,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/sort_rising" - android:textColor="@color/primaryTextColor" - android:textSize="18sp" - android:padding="16dp" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" android:clickable="true" android:focusable="true" android:background="?attr/selectableItemBackground" /> @@ -75,9 +85,10 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/sort_top" - android:textColor="@color/primaryTextColor" - android:textSize="18sp" - android:padding="16dp" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" android:clickable="true" android:focusable="true" android:background="?attr/selectableItemBackground" /> @@ -86,10 +97,11 @@ android:id="@+id/controversial_type_text_view_sort_type_bottom_sheet_fragment" android:layout_width="match_parent" android:layout_height="wrap_content" - android:text="@string/sort_rising" - android:textColor="@color/primaryTextColor" - android:textSize="18sp" - android:padding="16dp" + android:text="@string/sort_controversial" + android:paddingTop="16dp" + android:paddingBottom="16dp" + android:paddingStart="32dp" + android:paddingEnd="32dp" android:clickable="true" android:focusable="true" android:background="?attr/selectableItemBackground" /> diff --git a/app/src/main/res/layout/post_type_bottom_sheet.xml b/app/src/main/res/layout/post_type_bottom_sheet.xml deleted file mode 100644 index 092495c4..00000000 --- a/app/src/main/res/layout/post_type_bottom_sheet.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/sort_type_bottom_sheet.xml b/app/src/main/res/layout/sort_type_bottom_sheet.xml deleted file mode 100644 index 5951b431..00000000 --- a/app/src/main/res/layout/sort_type_bottom_sheet.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 1112f7b3..a4f27cd2 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -23,4 +23,6 @@ #FFFFFF @color/colorPrimaryDark + + #000000 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 5a6277cf..ddc21110 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -7,4 +7,7 @@ 16dp 180dp 16dp + 0dp + 0dp + 0dp \ No newline at end of file -- cgit v1.2.3