aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2019-12-11 05:27:48 +0000
committerGitHub <noreply@github.com>2019-12-11 05:27:48 +0000
commit2f5cdcbbdc0b83e05e9af5850ba01125710d7b30 (patch)
tree023de83387cfd51ea269085c339211b74d84be72 /app/src/main
parentf7eaa7ca06811e39b16dc80203f053e4cca118bc (diff)
parent9a8a549d69ba3049a58fc31e88b95d6445dd40d0 (diff)
downloadinfinity-for-reddit-2f5cdcbbdc0b83e05e9af5850ba01125710d7b30.tar
infinity-for-reddit-2f5cdcbbdc0b83e05e9af5850ba01125710d7b30.tar.gz
infinity-for-reddit-2f5cdcbbdc0b83e05e9af5850ba01125710d7b30.tar.bz2
infinity-for-reddit-2f5cdcbbdc0b83e05e9af5850ba01125710d7b30.tar.lz
infinity-for-reddit-2f5cdcbbdc0b83e05e9af5850ba01125710d7b30.tar.xz
infinity-for-reddit-2f5cdcbbdc0b83e05e9af5850ba01125710d7b30.tar.zst
infinity-for-reddit-2f5cdcbbdc0b83e05e9af5850ba01125710d7b30.zip
Merge pull request #41 from MartinSandfuchs/volume-scroll
Use volume keys to navigate posts
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java26
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/values/strings.xml1
-rw-r--r--app/src/main/res/xml/main_preferences.xml5
12 files changed, 110 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
index 8eaef666..2fcb2801 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
@@ -5,6 +5,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -160,6 +161,11 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
}
@Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ return ((FragmentCommunicator) mFragment).handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
+ }
+
+ @Override
public SharedPreferences getSharedPreferences() {
return mSharedPreferences;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
index f55086de..44f4014d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
@@ -5,6 +5,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -152,6 +153,11 @@ public class AccountSavedThingActivity extends BaseActivity {
}
@Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
+ }
+
+ @Override
public SharedPreferences getSharedPreferences() {
return mSharedPreferences;
}
@@ -339,6 +345,10 @@ public class AccountSavedThingActivity extends BaseActivity {
return fragment;
}
+ public boolean handleKeyDown(int keyCode) {
+ return viewPager.getCurrentItem() == 0 && postFragment.handleKeyDown(keyCode);
+ }
+
public void refresh() {
if (viewPager.getCurrentItem() == 0) {
if (postFragment != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
index 3c8160f9..b2c59ca9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
@@ -5,6 +5,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -177,6 +178,11 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
}
@Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ return ((FragmentCommunicator) mFragment).handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
+ }
+
+ @Override
public SharedPreferences getSharedPreferences() {
return mSharedPreferences;
}
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 a0c1883f..136f697c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
@@ -8,6 +8,7 @@ import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -864,6 +865,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
@Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
+ }
+
+ @Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(FETCH_USER_INFO_STATE, mFetchUserInfoSuccess);
@@ -1071,6 +1077,27 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
return fragment;
}
+ boolean handleKeyDown(int keyCode) {
+ if (mAccessToken == null) {
+ switch (viewPager.getCurrentItem()) {
+ case 0:
+ return popularPostFragment.handleKeyDown(keyCode);
+ case 1:
+ return allPostFragment.handleKeyDown(keyCode);
+ }
+ } else {
+ switch (viewPager.getCurrentItem()) {
+ case 0:
+ return frontPagePostFragment.handleKeyDown(keyCode);
+ case 1:
+ return popularPostFragment.handleKeyDown(keyCode);
+ case 2:
+ return allPostFragment.handleKeyDown(keyCode);
+ }
+ }
+ return false;
+ }
+
boolean startLazyMode() {
if (mAccessToken == null) {
switch (viewPager.getCurrentItem()) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
index beafad93..03684be1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
@@ -6,6 +6,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -171,6 +172,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
}
@Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
+ }
+
+ @Override
public SharedPreferences getSharedPreferences() {
return mSharedPreferences;
}
@@ -368,6 +374,10 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
return fragment;
}
+ public boolean handleKeyDown(int keyCode) {
+ return viewPager.getCurrentItem() == 0 && postFragment.handleKeyDown(keyCode);
+ }
+
void changeSortType(SortType sortType) {
mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
if(sortType.getTime() != null) {
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 5a8cbaff..6dcbc863 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -7,6 +7,7 @@ import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -323,6 +324,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
@Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ return ((FragmentCommunicator)(mFragment)).handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
+ }
+
+ @Override
public SharedPreferences getSharedPreferences() {
return mSharedPreferences;
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
index b4617196..5ffaa717 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
@@ -8,6 +8,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.util.TypedValue;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -397,6 +398,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
}
@Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ return sectionsPagerAdapter.handleKeyDown(keyCode) || super.onKeyDown(keyCode, event);
+ }
+
+ @Override
public SharedPreferences getSharedPreferences() {
return mSharedPreferences;
}
@@ -741,6 +747,10 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
return fragment;
}
+ public boolean handleKeyDown(int keyCode) {
+ return viewPager.getCurrentItem() == 0 && postFragment.handleKeyDown(keyCode);
+ }
+
public void refresh() {
if (viewPager.getCurrentItem() == 0) {
if (postFragment != null) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
index 53dcb587..17661c24 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -13,6 +13,7 @@ import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.util.TypedValue;
+import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -137,6 +138,31 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
+ private boolean scrollPostsByCount(int count) {
+ if (mLinearLayoutManager != null) {
+ int pos = mLinearLayoutManager.findFirstVisibleItemPosition();
+ int targetPosition = pos + count;
+ mLinearLayoutManager.scrollToPositionWithOffset(targetPosition, 0);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public boolean handleKeyDown(int keyCode) {
+ boolean volumeKeysNavigatePosts = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOLUME_KEYS_NAVIGATE_POSTS, false);
+ if (volumeKeysNavigatePosts) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_VOLUME_UP:
+ return scrollPostsByCount(-1);
+ case KeyEvent.KEYCODE_VOLUME_DOWN:
+ return scrollPostsByCount(1);
+ }
+ }
+ return false;
+ }
+
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java
index 5d66dc49..07cda1bb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java
@@ -3,6 +3,8 @@ package ml.docilealligator.infinityforreddit;
public interface FragmentCommunicator {
void refresh();
+ default boolean handleKeyDown(int keyCode) { return false; }
+
default void changeNSFW(boolean nsfw) {
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
index 8333db44..9e04530f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -59,4 +59,5 @@ public class SharedPreferencesUtils {
public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time";
public static final String SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL = "swipe_to_go_back_from_post_detail";
public static final String VOLUME_KEYS_NAVIGATE_COMMENTS = "volume_keys_navigate_comments";
+ public static final String VOLUME_KEYS_NAVIGATE_POSTS = "volume_keys_navigate_posts";
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 24bd34c7..8f1aa5ca 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -291,6 +291,7 @@
<string name="settings_immersive_interface_title">Immersive Interface</string>
<string name="settings_vote_buttons_on_the_right_title">Vote Buttons on the Right</string>
<string name="settings_volume_keys_navigate_comments_title">Use Volume Keys to Navigate Comments in Posts</string>
+ <string name="settings_volume_keys_navigate_posts_title">Use Volume Keys to Navigate Posts</string>
<string name="settings_show_elapsed_time">Show Elpased Time in Posts and Comments</string>
<string name="swipe_to_go_back_from_post_detail">Swipe Right to Go Back From Comments</string>
<string name="settings_lazy_mode_interval_title">Lazy Mode Interval</string>
diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml
index 894642fa..98e566eb 100644
--- a/app/src/main/res/xml/main_preferences.xml
+++ b/app/src/main/res/xml/main_preferences.xml
@@ -46,6 +46,11 @@
app:key="volume_keys_navigate_comments"
app:title="@string/settings_volume_keys_navigate_comments_title" />
+ <SwitchPreference
+ app:defaultValue="false"
+ app:key="volume_keys_navigate_posts"
+ app:title="@string/settings_volume_keys_navigate_posts_title" />
+
<Preference
app:title="@string/settings_font_size_title"
app:icon="@drawable/ic_font_size_24dp"