Changing lazy mode interval in Settings is now available.

This commit is contained in:
Alex Ning 2019-08-26 17:50:44 +08:00
parent b29bbf4321
commit 864eb21269
12 changed files with 77 additions and 79 deletions

View File

@ -150,7 +150,8 @@
<activity
android:name=".LoginActivity"
android:label="@string/login_activity_label"
android:parentActivityName=".MainActivity" />
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".ViewImageActivity"
android:parentActivityName=".MainActivity"

View File

@ -16,6 +16,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;
import org.json.JSONException;
import org.json.JSONObject;
@ -26,6 +27,8 @@ import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@ -38,6 +41,8 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
public class LoginActivity extends AppCompatActivity {
@BindView(R.id.toolbar_login_activity) Toolbar toolbar;
private String authCode;
@Inject
@ -59,8 +64,12 @@ public class LoginActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
((Infinity) getApplication()).getAppComponent().inject(this);
setSupportActionBar(toolbar);
boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
int themeType = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.THEME_KEY, "2"));
switch (themeType) {

View File

@ -1055,7 +1055,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
}
}
public void changeNSFW(boolean nsfw) {
void changeNSFW(boolean nsfw) {
if(frontPagePostFragment != null) {
frontPagePostFragment.changeNSFW(nsfw);
}

View File

@ -9,10 +9,11 @@ import androidx.core.app.NotificationManagerCompat;
class NotificationUtils {
static final String CHANNEL_POST_MEDIA = "Post Media";
static final String CHANNEL_ID_NEW_COMMENTS = "new_comments";
static final String CHANNEL_NEW_COMMENTS = "New Comments";
static final int SUMMARY_BASE_ID_UNREAD_MESSAGE = 0;
static final int NOTIFICATION_BASE_ID_UNREAD_MESSAGE = 1;
static final String CHANNEL_ID_NEW_MESSAGES = "new_messages";
static final String CHANNEL_NEW_MESSAGES = "New Messages";
private static final int SUMMARY_BASE_ID_UNREAD_MESSAGE = 0;
private static final int NOTIFICATION_BASE_ID_UNREAD_MESSAGE = 1;
private static final String GROUP_USER_BASE = "ml.docilealligator.infinityforreddit.";

View File

@ -86,6 +86,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private Runnable lazyModeRunnable;
private CountDownTimer resumeLazyModeCountDownTimer;
private float lazyModeInterval;
@Inject @Named("no_oauth")
Retrofit mRetrofit;
@ -124,6 +126,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
lazyModeHandler = new Handler();
lazyModeInterval = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.LAZY_MODE_INTERVAL_KEY, "2.5"));
smoothScroller = new LinearSmoothScroller(activity) {
@Override
protected int getVerticalSnapPreference() {
@ -157,11 +161,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mLinearLayoutManager.startSmoothScroll(smoothScroller);
}
}
lazyModeHandler.postDelayed(this, 2500);
lazyModeHandler.postDelayed(this, (long) (lazyModeInterval * 1000));
}
};
resumeLazyModeCountDownTimer = new CountDownTimer(2500, 2500) {
resumeLazyModeCountDownTimer = new CountDownTimer((long) (lazyModeInterval * 1000), (long) (lazyModeInterval * 1000)) {
@Override
public void onTick(long l) {
@ -416,9 +420,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
public void startLazyMode() {
isInLazyMode = true;
isLazyModePaused = false;
lazyModeHandler.postDelayed(lazyModeRunnable, 2500);
lazyModeInterval = Float.parseFloat(mSharedPreferences.getString(SharedPreferencesUtils.LAZY_MODE_INTERVAL_KEY, "2.5"));
lazyModeHandler.postDelayed(lazyModeRunnable, (long) (lazyModeInterval * 1000));
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Toast.makeText(activity, getString(R.string.lazy_mode_start, 2.5), Toast.LENGTH_SHORT).show();
Toast.makeText(activity, getString(R.string.lazy_mode_start, lazyModeInterval),
Toast.LENGTH_SHORT).show();
}
@Override
@ -439,7 +446,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if(resumeNow) {
lazyModeHandler.post(lazyModeRunnable);
} else {
lazyModeHandler.postDelayed(lazyModeRunnable, 2500);
lazyModeHandler.postDelayed(lazyModeRunnable, (long) (lazyModeInterval * 1000));
}
}
}

View File

@ -77,7 +77,7 @@ public class PullNotificationWorker extends Worker {
NotificationCompat.Builder summaryBuilder = NotificationUtils.buildSummaryNotification(context,
notificationManager, accountName,
context.getString(R.string.notification_new_messages, messages.size()),
NotificationUtils.CHANNEL_ID_NEW_COMMENTS, NotificationUtils.CHANNEL_NEW_COMMENTS,
NotificationUtils.CHANNEL_ID_NEW_MESSAGES, NotificationUtils.CHANNEL_NEW_MESSAGES,
NotificationUtils.getAccountGroupName(accountName));
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
@ -110,8 +110,8 @@ public class PullNotificationWorker extends Worker {
NotificationCompat.Builder builder = NotificationUtils.buildNotification(notificationManager,
context, title, message.getBody(), summary,
NotificationUtils.CHANNEL_ID_NEW_COMMENTS,
NotificationUtils.CHANNEL_NEW_COMMENTS,
NotificationUtils.CHANNEL_ID_NEW_MESSAGES,
NotificationUtils.CHANNEL_NEW_MESSAGES,
NotificationUtils.getAccountGroupName(accountName));
if(kind.equals(Message.TYPE_COMMENT)) {

View File

@ -7,6 +7,7 @@ package ml.docilealligator.infinityforreddit;
public class SharedPreferencesUtils {
public static final String ENABLE_NOTIFICATION_KEY = "enable_notification";
public static final String NOTIFICATION_INTERVAL_KEY = "notificaiton_interval";
public static final String LAZY_MODE_INTERVAL_KEY = "lazy_mode_interval";
public static final String NSFW_KEY = "nsfw";
public static final String THEME_KEY = "theme";
}

View File

@ -1,14 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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"
tools:application="ml.docilealligator.infinityforreddit.LoginActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_login_activity"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:navigationIcon="?attr/homeAsUpIndicator" />
</com.google.android.material.appbar.AppBarLayout>
<WebView
android:id="@+id/webview_login_activity"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -169,68 +169,6 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<!--<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="16dp">
<com.google.android.material.chip.Chip
android:id="@+id/type_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:textColor="@android:color/white"
android:layout_centerVertical="true"
app:chipBackgroundColor="@color/backgroundColorPrimaryDark"/>
<ImageView
android:id="@+id/gilded_image_view_item_post_detail"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_toEndOf="@id/type_text_view_item_post_detail"
android:layout_centerVertical="true"
android:visibility="gone"/>
<TextView
android:id="@+id/gilded_number_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="8dp"
android:layout_toEndOf="@id/gilded_image_view_item_post_detail"
android:layout_centerVertical="true"
android:visibility="gone"
android:textSize="20sp"
android:textColor="@color/gold"/>
<ImageView
android:id="@+id/crosspost_image_view_item_post_detail"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_toEndOf="@id/gilded_number_text_view_item_post_detail"
android:layout_centerVertical="true"
android:src="@drawable/crosspost"
android:tint="@color/colorAccent"
android:visibility="gone"/>
<com.google.android.material.chip.Chip
android:id="@+id/nsfw_text_view_item_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nsfw"
android:layout_alignParentEnd="true"
android:layout_marginStart="8dp"
android:textColor="@android:color/white"
android:visibility="gone"
android:layout_centerVertical="true"
app:chipBackgroundColor="@color/colorAccent"/>
</RelativeLayout>-->
<LinearLayout
android:id="@+id/spoiler_flair_linear_layout_item_post_detail"
android:layout_width="match_parent"

View File

@ -36,4 +36,20 @@
<item>1</item>
<item>2</item>
</string-array>
<string-array name="settings_lazy_mode_interval">
<item>2.5s</item>
<item>3s</item>
<item>5s</item>
<item>7s</item>
<item>10s</item>
</string-array>
<string-array name="settings_lazy_mode_interval_values">
<item>2.5</item>
<item>3</item>
<item>5</item>
<item>7</item>
<item>10</item>
</string-array>
</resources>

View File

@ -258,6 +258,7 @@
<string name="settings_theme_light__theme_summary">Light Theme</string>
<string name="settings_theme_dark_theme_summary">Dark Theme</string>
<string name="settings_theme_system_default_summary">Device default</string>
<string name="settings_lazy_mode_interval_title">Lazy Mode Interval</string>
<string name="settings_enable_nsfw_title">Enable NSFW</string>
<string name="settings_acknowledgement_master_title">Acknowledgement</string>

View File

@ -16,6 +16,15 @@
app:title="@string/settings_theme_title"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="2.5"
android:entries="@array/settings_lazy_mode_interval"
app:entryValues="@array/settings_lazy_mode_interval_values"
app:key="lazy_mode_interval"
app:icon="@drawable/ic_outline_access_time_24px"
app:title="@string/settings_lazy_mode_interval_title"
app:useSimpleSummaryProvider="true" />
<SwitchPreference
app:defaultValue="false"
app:key="nsfw"