aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2020-06-16 07:26:51 +0000
committerGitHub <noreply@github.com>2020-06-16 07:26:51 +0000
commit62879f8dc2ad9abc514939586ccda01806538933 (patch)
treea5fdd0d89c68ddd2cd104d57629a70d8f18b036a /app/src
parent49c2c7a7467a1202760b9763e5fcbb1fb1d982a3 (diff)
parentfea972727c60f623bd8062868e94fc866e1096b0 (diff)
downloadinfinity-for-reddit-62879f8dc2ad9abc514939586ccda01806538933.tar
infinity-for-reddit-62879f8dc2ad9abc514939586ccda01806538933.tar.gz
infinity-for-reddit-62879f8dc2ad9abc514939586ccda01806538933.tar.bz2
infinity-for-reddit-62879f8dc2ad9abc514939586ccda01806538933.tar.lz
infinity-for-reddit-62879f8dc2ad9abc514939586ccda01806538933.tar.xz
infinity-for-reddit-62879f8dc2ad9abc514939586ccda01806538933.tar.zst
infinity-for-reddit-62879f8dc2ad9abc514939586ccda01806538933.zip
Merge branch 'master' into refactor-view-image
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/AndroidManifest.xml4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java251
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SetAsWallpaperAsyncTask.java98
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java5
-rw-r--r--app/src/main/res/anim/slide_out_down.xml12
-rw-r--r--app/src/main/res/anim/slide_out_up.xml12
-rw-r--r--app/src/main/res/layout/activity_view_sidebar.xml50
-rw-r--r--app/src/main/res/menu/view_sidebar_activity.xml10
-rw-r--r--app/src/main/res/menu/view_subreddit_detail_activity.xml8
15 files changed, 155 insertions, 338 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 829f2f2b..f26d5ef7 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -75,10 +75,6 @@
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustResize" />
<activity
- android:name=".Activity.ViewSidebarActivity"
- android:parentActivityName=".Activity.MainActivity"
- android:theme="@style/AppTheme.NoActionBar" />
- <activity
android:name=".Activity.ViewMultiRedditDetailActivity"
android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java
index e6fb7c3d..45c310c0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java
@@ -159,8 +159,9 @@ public class LinkResolverActivity extends AppCompatActivity {
intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName);
startActivity(intent);
} else if (path.matches(SIDEBAR_PATTERN)) {
- Intent intent = new Intent(this, ViewSidebarActivity.class);
- intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14));
+ Intent intent = new Intent(this, ViewSubredditDetailActivity.class);
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3, path.length() - 14));
+ intent.putExtra(ViewSubredditDetailActivity.EXTRA_VIEW_SIDEBAR, true);
startActivity(intent);
} else if (path.matches(MULTIREDDIT_PATTERN)) {
Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java
index 03deb8ff..ee4ecb8d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java
@@ -36,6 +36,7 @@ import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
+import com.thefuntasty.hauler.DragDirection;
import com.thefuntasty.hauler.HaulerView;
import java.io.File;
@@ -150,6 +151,12 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
setTitle("");
}
+ mHaulerView.setOnDragDismissedListener(dragDirection -> {
+ int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down;
+ finish();
+ overridePendingTransition(0, slide);
+ });
+
mLoadErrorLinearLayout.setOnClickListener(view -> {
mProgressBar.setVisibility(View.VISIBLE);
mLoadErrorLinearLayout.setVisibility(View.GONE);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
index d14886ff..bf56ffac 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImgurMediaActivity.java
@@ -19,6 +19,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
+import com.thefuntasty.hauler.DragDirection;
import com.thefuntasty.hauler.HaulerView;
import org.json.JSONArray;
@@ -130,7 +131,11 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
images = savedInstanceState.getParcelableArrayList(IMGUR_IMAGES_STATE);
}
- haulerView.setOnDragDismissedListener(dragDirection -> finish());
+ haulerView.setOnDragDismissedListener(dragDirection -> {
+ int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down;
+ finish();
+ overridePendingTransition(0, slide);
+ });
if (images == null) {
fetchImgurMedia(imgurId);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java
deleted file mode 100644
index 826ba33d..00000000
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java
+++ /dev/null
@@ -1,251 +0,0 @@
-package ml.docilealligator.infinityforreddit.Activity;
-
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.text.Spanned;
-import android.text.style.SuperscriptSpan;
-import android.text.util.Linkify;
-import android.util.TypedValue;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.Window;
-import android.view.WindowManager;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.widget.Toolbar;
-import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.lifecycle.ViewModelProvider;
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
-
-import com.google.android.material.appbar.AppBarLayout;
-
-import org.commonmark.ext.gfm.tables.TableBlock;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import io.noties.markwon.AbstractMarkwonPlugin;
-import io.noties.markwon.Markwon;
-import io.noties.markwon.MarkwonConfiguration;
-import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
-import io.noties.markwon.linkify.LinkifyPlugin;
-import io.noties.markwon.recycler.MarkwonAdapter;
-import io.noties.markwon.recycler.table.TableEntry;
-import io.noties.markwon.recycler.table.TableEntryPlugin;
-import io.noties.markwon.simple.ext.SimpleExtPlugin;
-import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
-import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
-import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask;
-import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.FetchSubredditData;
-import ml.docilealligator.infinityforreddit.Infinity;
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
-import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
-import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
-import retrofit2.Retrofit;
-
-public class ViewSidebarActivity extends BaseActivity implements ActivityToolbarInterface {
-
- public static final String EXTRA_SUBREDDIT_NAME = "ESN";
- @BindView(R.id.coordinator_layout_view_sidebar_activity)
- CoordinatorLayout coordinatorLayout;
- @BindView(R.id.appbar_layout_view_sidebar_activity)
- AppBarLayout appBarLayout;
- @BindView(R.id.toolbar_view_sidebar_activity)
- Toolbar toolbar;
- @BindView(R.id.swipe_refresh_layout_view_sidebar_activity)
- SwipeRefreshLayout swipeRefreshLayout;
- @BindView(R.id.markdown_recycler_view_view_sidebar_activity)
- RecyclerView markdownRecyclerView;
- @Inject
- @Named("no_oauth")
- Retrofit mRetrofit;
- @Inject
- RedditDataRoomDatabase mRedditDataRoomDatabase;
- @Inject
- @Named("default")
- SharedPreferences mSharedPreferences;
- @Inject
- CustomThemeWrapper mCustomThemeWrapper;
- public SubredditViewModel mSubredditViewModel;
- private LinearLayoutManager mLinearLayoutManager;
- private String subredditName;
- private int markdownColor;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- ((Infinity) getApplication()).getAppComponent().inject(this);
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_view_sidebar);
-
- ButterKnife.bind(this);
-
- applyCustomTheme();
-
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- Window window = getWindow();
-
- if (isChangeStatusBarIconColor()) {
- addOnOffsetChangedListener(appBarLayout);
- }
-
- if (isImmersiveInterface()) {
- window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- adjustToolbar(toolbar);
-
- int navBarHeight = getNavBarHeight();
- if (navBarHeight > 0) {
- int px = (int) TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP,
- 16,
- getResources().getDisplayMetrics()
- );
- markdownRecyclerView.setPadding(px, px, px, navBarHeight);
- }
- }
- }
-
- subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
- if (subredditName == null) {
- Toast.makeText(this, R.string.error_getting_subreddit_name, Toast.LENGTH_SHORT).show();
- finish();
- return;
- }
-
- toolbar.setTitle("r/" + subredditName);
- setSupportActionBar(toolbar);
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- setToolbarGoToTop(toolbar);
-
- Markwon markwon = Markwon.builder(this)
- .usePlugin(new AbstractMarkwonPlugin() {
- @Override
- public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
- textView.setTextColor(markdownColor);
- }
-
- @Override
- public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
- builder.linkResolver((view, link) -> {
- Intent intent = new Intent(ViewSidebarActivity.this, LinkResolverActivity.class);
- Uri uri = Uri.parse(link);
- if (uri.getScheme() == null && uri.getHost() == null) {
- intent.setData(LinkResolverActivity.getRedditUriByPath(link));
- } else {
- intent.setData(uri);
- }
- ViewSidebarActivity.this.startActivity(intent);
- }).urlProcessor(new UrlProcessorRelativeToAbsolute("https://www.reddit.com"));
- }
- })
- .usePlugin(StrikethroughPlugin.create())
- .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
- .usePlugin(SimpleExtPlugin.create(plugin ->
- plugin.addExtension(1, '^', (configuration, props) -> {
- return new SuperscriptSpan();
- })
- )
- )
- .usePlugin(TableEntryPlugin.create(this))
- .build();
- MarkwonAdapter markwonAdapter = MarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text)
- .include(TableBlock.class, TableEntry.create(builder -> builder
- .tableLayout(R.layout.adapter_table_block, R.id.table_layout)
- .textLayoutIsRoot(R.layout.view_table_entry_cell)))
- .build();
-
- mLinearLayoutManager = new LinearLayoutManager(this);
- markdownRecyclerView.setLayoutManager(mLinearLayoutManager);
- markdownRecyclerView.setAdapter(markwonAdapter);
-
- mSubredditViewModel = new ViewModelProvider(this,
- new SubredditViewModel.Factory(getApplication(), mRedditDataRoomDatabase, subredditName))
- .get(SubredditViewModel.class);
- mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
- if (subredditData != null) {
- if (subredditData.getSidebarDescription() != null && !subredditData.getSidebarDescription().equals("")) {
- markwonAdapter.setMarkdown(markwon, subredditData.getSidebarDescription());
- markwonAdapter.notifyDataSetChanged();
- }
- } else {
- fetchSubredditData();
- }
- });
-
- swipeRefreshLayout.setOnRefreshListener(this::fetchSubredditData);
- }
-
- private void fetchSubredditData() {
- swipeRefreshLayout.setRefreshing(true);
- FetchSubredditData.fetchSubredditData(mRetrofit, subredditName, new FetchSubredditData.FetchSubredditDataListener() {
- @Override
- public void onFetchSubredditDataSuccess(SubredditData subredditData, int nCurrentOnlineSubscribers) {
- swipeRefreshLayout.setRefreshing(false);
- new InsertSubredditDataAsyncTask(mRedditDataRoomDatabase, subredditData, () -> swipeRefreshLayout.setRefreshing(false)).execute();
- }
-
- @Override
- public void onFetchSubredditDataFail() {
- swipeRefreshLayout.setRefreshing(false);
- Toast.makeText(ViewSidebarActivity.this, R.string.cannot_fetch_sidebar, Toast.LENGTH_SHORT).show();
- }
- });
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.view_sidebar_activity, menu);
- applyMenuItemTheme(menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- if (item.getItemId() == android.R.id.home) {
- finish();
- return true;
- } else if (item.getItemId() == R.id.action_refresh_view_sidebar_activity) {
- if (!swipeRefreshLayout.isRefreshing()) {
- fetchSubredditData();
- }
- return true;
- }
- return false;
- }
-
- @Override
- public SharedPreferences getSharedPreferences() {
- return mSharedPreferences;
- }
-
- @Override
- protected CustomThemeWrapper getCustomThemeWrapper() {
- return mCustomThemeWrapper;
- }
-
- @Override
- protected void applyCustomTheme() {
- coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
- applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
- swipeRefreshLayout.setProgressBackgroundColorSchemeColor(mCustomThemeWrapper.getCircularProgressBarBackground());
- swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
- markdownColor = mCustomThemeWrapper.getSecondaryTextColor();
- }
-
- @Override
- public void onLongPress() {
- if (mLinearLayoutManager != null) {
- mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
- }
- }
-}
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 439c976e..1accdeec 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -90,6 +90,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN";
public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
+ public static final String EXTRA_VIEW_SIDEBAR = "EVSB";
private static final String FETCH_SUBREDDIT_INFO_STATE = "FSIS";
private static final String CURRENT_ONLINE_SUBSCRIBERS_STATE = "COSS";
@@ -627,6 +628,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
viewPager.setOffscreenPageLimit(2);
tabLayout.setupWithViewPager(viewPager);
+
+ boolean viewSidebar = getIntent().getBooleanExtra(EXTRA_VIEW_SIDEBAR, false);
+ if (viewSidebar) {
+ viewPager.setCurrentItem(1, false);
+ }
+
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@@ -726,11 +733,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
case R.id.action_change_post_layout_view_subreddit_detail_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
- case R.id.action_view_side_bar_view_subreddit_detail_activity:
- Intent sidebarIntent = new Intent(this, ViewSidebarActivity.class);
- sidebarIntent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, subredditName);
- startActivity(sidebarIntent);
- return true;
case R.id.action_share_view_subreddit_detail_activity:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
index 5bb95350..56e01c27 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java
@@ -44,6 +44,7 @@ import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
+import com.thefuntasty.hauler.DragDirection;
import com.thefuntasty.hauler.HaulerView;
import javax.inject.Inject;
@@ -158,7 +159,13 @@ public class ViewVideoActivity extends AppCompatActivity {
params.rightMargin = getResources().getDimensionPixelSize(resourceId);
}
- haulerView.setOnDragDismissedListener(dragDirection -> finish());
+ haulerView.setOnDragDismissedListener(dragDirection -> {
+ int slide = dragDirection == DragDirection.UP ? R.anim.slide_out_up : R.anim.slide_out_down;
+ finish();
+ overridePendingTransition(0, slide);
+ });
+
+ mediaDownloader = new MediaDownloaderImpl();
mediaDownloader = new MediaDownloaderImpl();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 97309123..9e763433 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -37,7 +37,6 @@ import ml.docilealligator.infinityforreddit.Activity.ViewImgurMediaActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewMessageActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewMultiRedditDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity;
-import ml.docilealligator.infinityforreddit.Activity.ViewSidebarActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewVideoActivity;
@@ -139,8 +138,6 @@ public interface AppComponent {
void inject(ViewMultiRedditDetailActivity viewMultiRedditDetailActivity);
- void inject(ViewSidebarActivity viewSidebarActivity);
-
void inject(ViewVideoActivity viewVideoActivity);
void inject(GesturesAndButtonsPreferenceFragment gesturesAndButtonsPreferenceFragment);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SetAsWallpaperAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SetAsWallpaperAsyncTask.java
new file mode 100644
index 00000000..9e3aa8f5
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/SetAsWallpaperAsyncTask.java
@@ -0,0 +1,98 @@
+package ml.docilealligator.infinityforreddit.AsyncTask;
+
+import android.app.WallpaperManager;
+import android.graphics.Bitmap;
+import android.graphics.Rect;
+import android.media.ThumbnailUtils;
+import android.os.AsyncTask;
+import android.os.Build;
+import android.util.DisplayMetrics;
+import android.view.WindowManager;
+
+import java.io.IOException;
+
+public class SetAsWallpaperAsyncTask extends AsyncTask<Void, Void, Void> {
+
+ private Bitmap bitmap;
+ private int setTo;
+ private WallpaperManager manager;
+ private WindowManager windowManager;
+ private SetAsWallpaperAsyncTaskListener setAsWallpaperAsyncTaskListener;
+ private boolean success = true;
+
+ public SetAsWallpaperAsyncTask(Bitmap bitmap, int setTo, WallpaperManager manager, WindowManager windowManager,
+ SetAsWallpaperAsyncTaskListener setAsWallpaperAsyncTaskListener) {
+ this.bitmap = bitmap;
+ this.setTo = setTo;
+ this.manager = manager;
+ this.windowManager = windowManager;
+ this.setAsWallpaperAsyncTaskListener = setAsWallpaperAsyncTaskListener;
+ }
+
+ public interface SetAsWallpaperAsyncTaskListener {
+ void success();
+ void failed();
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ DisplayMetrics metrics = new DisplayMetrics();
+ Rect rect = null;
+
+ if (windowManager != null) {
+ windowManager.getDefaultDisplay().getMetrics(metrics);
+ int height = metrics.heightPixels;
+ int width = metrics.widthPixels;
+
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
+ bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height);
+ }
+
+ float imageAR = (float) bitmap.getWidth() / (float) bitmap.getHeight();
+ float screenAR = (float) width / (float) height;
+
+ if (imageAR > screenAR) {
+ int desiredWidth = (int) (bitmap.getHeight() * screenAR);
+ rect = new Rect((bitmap.getWidth() - desiredWidth) / 2, 0, bitmap.getWidth(), bitmap.getHeight());
+ } else {
+ int desiredHeight = (int) (bitmap.getWidth() / screenAR);
+ rect = new Rect(0, (bitmap.getHeight() - desiredHeight) / 2, bitmap.getWidth(), (bitmap.getHeight() + desiredHeight) / 2);
+ }
+ }
+ try {
+ switch (setTo) {
+ case 0:
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ manager.setBitmap(bitmap, rect, true, WallpaperManager.FLAG_SYSTEM);
+ }
+ break;
+ case 1:
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ manager.setBitmap(bitmap, rect, true, WallpaperManager.FLAG_LOCK);
+ }
+ break;
+ case 2:
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ manager.setBitmap(bitmap, rect, true, WallpaperManager.FLAG_SYSTEM | WallpaperManager.FLAG_LOCK);
+ } else {
+ manager.setBitmap(bitmap);
+ }
+ break;
+ }
+ } catch (IOException e) {
+ success = false;
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ if (success) {
+ setAsWallpaperAsyncTaskListener.success();
+ } else {
+ setAsWallpaperAsyncTaskListener.failed();
+ }
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
index dbafed2d..9d9aa9b7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
@@ -50,9 +50,6 @@ import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
import retrofit2.Retrofit;
-/**
- * A simple {@link Fragment} subclass.
- */
public class SidebarFragment extends Fragment {
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
@@ -152,7 +149,7 @@ public class SidebarFragment extends Fragment {
mSubredditViewModel = new ViewModelProvider(this,
new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, subredditName))
.get(SubredditViewModel.class);
- mSubredditViewModel.getSubredditLiveData().observe(this, subredditData -> {
+ mSubredditViewModel.getSubredditLiveData().observe(getViewLifecycleOwner(), subredditData -> {
if (subredditData != null) {
if (subredditData.getSidebarDescription() != null && !subredditData.getSidebarDescription().equals("")) {
markwonAdapter.setMarkdown(markwon, subredditData.getSidebarDescription());
diff --git a/app/src/main/res/anim/slide_out_down.xml b/app/src/main/res/anim/slide_out_down.xml
new file mode 100644
index 00000000..4c64d6c4
--- /dev/null
+++ b/app/src/main/res/anim/slide_out_down.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate
+ android:duration="@android:integer/config_shortAnimTime"
+ android:fromYDelta="0"
+ android:toYDelta="+50%p" />
+ <alpha
+ android:duration="@android:integer/config_shortAnimTime"
+ android:fromAlpha="1.0"
+ android:toAlpha="0.0" />
+</set>
diff --git a/app/src/main/res/anim/slide_out_up.xml b/app/src/main/res/anim/slide_out_up.xml
new file mode 100644
index 00000000..945e2b7e
--- /dev/null
+++ b/app/src/main/res/anim/slide_out_up.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <translate
+ android:duration="@android:integer/config_shortAnimTime"
+ android:fromYDelta="0"
+ android:toYDelta="-50%p" />
+ <alpha
+ android:duration="@android:integer/config_shortAnimTime"
+ android:fromAlpha="1.0"
+ android:toAlpha="0.0" />
+</set>
diff --git a/app/src/main/res/layout/activity_view_sidebar.xml b/app/src/main/res/layout/activity_view_sidebar.xml
deleted file mode 100644
index 94a120ef..00000000
--- a/app/src/main/res/layout/activity_view_sidebar.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/coordinator_layout_view_sidebar_activity"
- tools:context=".Activity.ViewSidebarActivity">
-
- <com.google.android.material.appbar.AppBarLayout
- android:id="@+id/appbar_layout_view_sidebar_activity"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:theme="@style/AppTheme.AppBarOverlay">
-
- <com.google.android.material.appbar.CollapsingToolbarLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:layout_scrollFlags="scroll|enterAlways"
- app:titleEnabled="false"
- app:toolbarId="@+id/toolbar_view_sidebar_activity">
-
- <androidx.appcompat.widget.Toolbar
- android:id="@+id/toolbar_view_sidebar_activity"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?attr/actionBarSize"
- app:popupTheme="@style/AppTheme.PopupOverlay"
- app:navigationIcon="?attr/homeAsUpIndicator" />
-
- </com.google.android.material.appbar.CollapsingToolbarLayout>
-
- </com.google.android.material.appbar.AppBarLayout>
-
- <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
- android:id="@+id/swipe_refresh_layout_view_sidebar_activity"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:layout_behavior="@string/appbar_scrolling_view_behavior">
-
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/markdown_recycler_view_view_sidebar_activity"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:padding="16dp"
- android:clipToPadding="false" />
-
- </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
-
-</androidx.coordinatorlayout.widget.CoordinatorLayout> \ No newline at end of file
diff --git a/app/src/main/res/menu/view_sidebar_activity.xml b/app/src/main/res/menu/view_sidebar_activity.xml
deleted file mode 100644
index fa5d9123..00000000
--- a/app/src/main/res/menu/view_sidebar_activity.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<menu xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto">
- <item
- android:id="@+id/action_refresh_view_sidebar_activity"
- android:orderInCategory="1"
- android:title="@string/action_refresh"
- android:icon="@drawable/ic_refresh_toolbar_24dp"
- app:showAsAction="ifRoom" />
-</menu> \ No newline at end of file
diff --git a/app/src/main/res/menu/view_subreddit_detail_activity.xml b/app/src/main/res/menu/view_subreddit_detail_activity.xml
index 9365ed2e..daea0d09 100644
--- a/app/src/main/res/menu/view_subreddit_detail_activity.xml
+++ b/app/src/main/res/menu/view_subreddit_detail_activity.xml
@@ -35,14 +35,8 @@
app:showAsAction="never" />
<item
- android:id="@+id/action_view_side_bar_view_subreddit_detail_activity"
- android:orderInCategory="6"
- android:title="@string/action_view_side_bar"
- app:showAsAction="never" />
-
- <item
android:id="@+id/action_share_view_subreddit_detail_activity"
android:orderInCategory="7"
android:title="@string/action_share"
app:showAsAction="never" />
-</menu> \ No newline at end of file
+</menu>