Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
feat: 新增设置是否允许滑动时加载图片
Browse files Browse the repository at this point in the history
  • Loading branch information
HuanCheng65 committed Aug 5, 2020
1 parent 88ee873 commit 1d15d51
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 64 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ dependencies {

//AndroidX
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta8'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-rc1'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
Expand All @@ -128,7 +128,7 @@ dependencies {
kapt 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0'

implementation 'com.google.android.material:material:1.2.0-beta01'
implementation 'com.google.android.material:material:1.3.0-alpha02'

implementation 'com.squareup.okhttp3:okhttp:4.5.0'
implementation 'com.squareup.retrofit2:retrofit:2.8.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
Expand All @@ -30,7 +29,6 @@
import androidx.appcompat.app.AlertDialog;
import androidx.viewpager.widget.ViewPager;

import com.flurry.android.FlurryAgent;
import com.google.android.material.bottomnavigation.BottomNavigationItemView;
import com.google.android.material.bottomnavigation.BottomNavigationMenuView;
import com.google.android.material.bottomnavigation.BottomNavigationView;
Expand All @@ -41,7 +39,6 @@
import com.huanchengfly.tieba.api.interfaces.CommonCallback;
import com.huanchengfly.tieba.api.models.ChangelogBean;
import com.huanchengfly.tieba.api.models.NewUpdateBean;
import com.huanchengfly.tieba.post.activities.AboutActivity;
import com.huanchengfly.tieba.post.activities.NewIntroActivity;
import com.huanchengfly.tieba.post.activities.UpdateInfoActivity;
import com.huanchengfly.tieba.post.activities.base.BaseActivity;
Expand Down Expand Up @@ -104,11 +101,11 @@ public void onResume() {
.getBoolean("follow_system_night", false) && !TextUtils.equals(reason, ThemeUtil.REASON_MANUALLY);
if (followSystemNight) {
if (BaseApplication.isSystemNight() && !ThemeUtil.isNightMode(this)) {
ThemeUtil.switchToNightMode(this, ThemeUtil.REASON_FOLLOW_SYSTEM, false);
SharedPreferencesUtil.put(ThemeUtil.getSharedPreferences(this), SP_SHOULD_SHOW_SNACKBAR, true);
ThemeUtil.switchToNightMode(this, ThemeUtil.REASON_FOLLOW_SYSTEM, false);
} else if (!BaseApplication.isSystemNight() && ThemeUtil.isNightMode(this) && TextUtils.equals(reason, ThemeUtil.REASON_FOLLOW_SYSTEM)) {
ThemeUtil.switchFromNightMode(this, ThemeUtil.REASON_FOLLOW_SYSTEM, false);
SharedPreferencesUtil.put(ThemeUtil.getSharedPreferences(this), SP_SHOULD_SHOW_SNACKBAR, true);
ThemeUtil.switchFromNightMode(this, ThemeUtil.REASON_FOLLOW_SYSTEM, false);
}
}
super.onResume();
Expand Down
30 changes: 16 additions & 14 deletions app/src/main/java/com/huanchengfly/tieba/post/ThreadActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,23 @@ class ThreadActivity : BaseActivity(), View.OnClickListener {
addItemDecoration(ThreadDivider(this@ThreadActivity))
layoutManager = mLayoutManager
adapter = mAdapter
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (!Util.canLoadGlide(this@ThreadActivity)) {
return
}
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Glide.with(this@ThreadActivity)
.resumeRequests()
} else {
Glide.with(this@ThreadActivity)
.pauseRequests()
if (!appPreferences.loadPictureWhenScroll) {
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (!Util.canLoadGlide(this@ThreadActivity)) {
return
}
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Glide.with(this@ThreadActivity)
.resumeRequests()
} else {
Glide.with(this@ThreadActivity)
.pauseRequests()
}
}
}
})
})
}
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
refreshTitle()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.huanchengfly.tieba.post.R;
import com.huanchengfly.tieba.post.base.BaseApplication;
import com.huanchengfly.tieba.post.base.Config;
import com.huanchengfly.tieba.post.utils.AppPreferencesUtils;
import com.huanchengfly.tieba.post.utils.HandleBackUtil;
import com.huanchengfly.tieba.post.utils.SharedPreferencesUtil;
import com.huanchengfly.tieba.post.utils.ThemeUtil;
Expand All @@ -54,6 +55,10 @@ protected int getLayoutId() {
return NO_LAYOUT;
}

protected AppPreferencesUtils getAppPreferences() {
return new AppPreferencesUtils(this);
}

@Override
protected void onPause() {
super.onPause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatDelegate;

import com.billy.android.preloader.PreLoader;
import com.flurry.android.FlurryAgent;
import com.huanchengfly.theme.interfaces.ThemeSwitcher;
import com.huanchengfly.theme.utils.ThemeUtils;
Expand All @@ -35,7 +34,6 @@
import com.huanchengfly.tieba.post.utils.SharedPreferencesUtil;
import com.huanchengfly.tieba.post.utils.ThemeUtil;
import com.huanchengfly.tieba.post.utils.Util;
import com.huanchengfly.tieba.post.utils.preload.loaders.LikeForumListLoader;
import com.huanchengfly.utils.MD5Util;

import org.intellij.lang.annotations.RegExp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.huanchengfly.tieba.post.interfaces.BackHandledInterface;
import com.huanchengfly.tieba.post.interfaces.Refreshable;
import com.huanchengfly.tieba.post.utils.AppPreferencesUtils;
import com.huanchengfly.tieba.post.utils.HandleBackUtil;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -49,6 +50,10 @@ public boolean isFirstVisible() {
return isFirstVisible;
}

protected AppPreferencesUtils getAppPreferences() {
return new AppPreferencesUtils(attachContext);
}

@TargetApi(23)
@Override
public void onAttach(Context context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.huanchengfly.tieba.post.fragments

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
Expand Down Expand Up @@ -127,21 +126,23 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab
layoutManager = MyLinearLayoutManager(attachContext)
addItemDecoration(ForumDivider(attachContext, LinearLayoutManager.VERTICAL))
adapter = mAdapter
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (!Util.canLoadGlide(attachContext)) {
return
}
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Glide.with(attachContext)
.resumeRequests()
} else {
Glide.with(attachContext)
.pauseRequests()
if (!appPreferences.loadPictureWhenScroll) {
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (!Util.canLoadGlide(attachContext)) {
return
}
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Glide.with(attachContext)
.resumeRequests()
} else {
Glide.with(attachContext)
.pauseRequests()
}
}
}
})
})
}
addOnChildAttachStateChangeListener(object : OnChildAttachStateChangeListener {
override fun onChildViewAttachedToWindow(view: View) {}
override fun onChildViewDetachedFromWindow(view: View) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,23 @@ class PersonalizedFeedFragment : BaseFragment(), PersonalizedFeedAdapter.OnRefre
}
recyclerView.apply {
addItemDecoration(FeedDivider(attachContext))
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (!Util.canLoadGlide(attachContext)) {
return
}
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Glide.with(attachContext)
.resumeRequests()
} else {
Glide.with(attachContext)
.pauseRequests()
if (!appPreferences.loadPictureWhenScroll) {
addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
super.onScrollStateChanged(recyclerView, newState)
if (!Util.canLoadGlide(attachContext)) {
return
}
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
Glide.with(attachContext)
.resumeRequests()
} else {
Glide.with(attachContext)
.pauseRequests()
}
}
}
})
})
}
addOnChildAttachStateChangeListener(object : OnChildAttachStateChangeListener {
override fun onChildViewAttachedToWindow(view: View) {}
override fun onChildViewDetachedFromWindow(view: View) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package com.huanchengfly.tieba.post.utils

import android.content.Context
import android.content.SharedPreferences
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

open class AppPreferencesUtils(context: Context) {
private val preferences: SharedPreferences =
context.getSharedPreferences("settings", Context.MODE_PRIVATE)
//PreferenceManager.getDefaultSharedPreferences(context)

var loadPictureWhenScroll by SharedPreferenceDelegates.boolean(true)

private object SharedPreferenceDelegates {
fun int(defaultValue: Int = 0) = object : ReadWriteProperty<AppPreferencesUtils, Int> {
override fun getValue(thisRef: AppPreferencesUtils, property: KProperty<*>): Int {
return thisRef.preferences.getInt(property.name, defaultValue)
}

override fun setValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>,
value: Int
) {
thisRef.preferences.edit().putInt(property.name, value).apply()
}
}

fun long(defaultValue: Long = 0L) =
object : ReadWriteProperty<AppPreferencesUtils, Long> {
override fun getValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>
): Long {
return thisRef.preferences.getLong(property.name, defaultValue)
}

override fun setValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>,
value: Long
) {
thisRef.preferences.edit().putLong(property.name, value).apply()
}
}

fun boolean(defaultValue: Boolean = false) =
object : ReadWriteProperty<AppPreferencesUtils, Boolean> {
override fun getValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>
): Boolean {
return thisRef.preferences.getBoolean(property.name, defaultValue)
}

override fun setValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>,
value: Boolean
) {
thisRef.preferences.edit().putBoolean(property.name, value).apply()
}
}

fun float(defaultValue: Float = 0.0f) =
object : ReadWriteProperty<AppPreferencesUtils, Float> {
override fun getValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>
): Float {
return thisRef.preferences.getFloat(property.name, defaultValue)
}

override fun setValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>,
value: Float
) {
thisRef.preferences.edit().putFloat(property.name, value).apply()
}
}

fun string(defaultValue: String? = null) =
object : ReadWriteProperty<AppPreferencesUtils, String?> {
override fun getValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>
): String? {
return thisRef.preferences.getString(property.name, defaultValue)
}

override fun setValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>,
value: String?
) {
thisRef.preferences.edit().putString(property.name, value).apply()
}
}

fun stringSet(defaultValue: Set<String>? = null) =
object : ReadWriteProperty<AppPreferencesUtils, Set<String>?> {
override fun getValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>
): Set<String>? {
return thisRef.preferences.getStringSet(property.name, defaultValue)
}

override fun setValue(
thisRef: AppPreferencesUtils,
property: KProperty<*>,
value: Set<String>?
) {
thisRef.preferences.edit().putStringSet(property.name, value).apply()
}
}
}

val Context.appPreferences: AppPreferencesUtils
get() = AppPreferencesUtils(this)
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_round_hourglass_full.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M6,4v3.17c0,0.53 0.21,1.04 0.59,1.42L10,12l-3.42,3.42c-0.37,0.38 -0.58,0.89 -0.58,1.42V20c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2v-3.16c0,-0.53 -0.21,-1.04 -0.58,-1.41L14,12l3.41,-3.4c0.38,-0.38 0.59,-0.89 0.59,-1.42V4c0,-1.1 -0.9,-2 -2,-2H8c-1.1,0 -2,0.9 -2,2z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_round_outlet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12c0,5.52 4.48,10 10,10s10,-4.48 10,-10C22,6.48 17.52,2 12,2zM9,12c-0.55,0 -1,-0.45 -1,-1V8c0,-0.55 0.45,-1 1,-1s1,0.45 1,1v3C10,11.55 9.55,12 9,12zM13,18h-2c-0.55,0 -1,-0.45 -1,-1v-0.89c0,-1 0.68,-1.92 1.66,-2.08C12.92,13.82 14,14.79 14,16v1C14,17.55 13.55,18 13,18zM16,11c0,0.55 -0.45,1 -1,1c-0.55,0 -1,-0.45 -1,-1V8c0,-0.55 0.45,-1 1,-1c0.55,0 1,0.45 1,1V11z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_round_rounded_corner.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M19,19h2v2h-2v-2zM19,17h2v-2h-2v2zM3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM3,5h2L5,3L3,3v2zM7,5h2L9,3L7,3v2zM15,21h2v-2h-2v2zM11,21h2v-2h-2v2zM15,21h2v-2h-2v2zM7,21h2v-2L7,19v2zM3,21h2v-2L3,19v2zM21,8c0,-2.76 -2.24,-5 -5,-5h-5v2h5c1.65,0 3,1.35 3,3v5h2L21,8z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_round_verified.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M23,12l-2.44,-2.79l0.34,-3.69l-3.61,-0.82L15.4,1.5L12,2.96L8.6,1.5L6.71,4.69L3.1,5.5L3.44,9.2L1,12l2.44,2.79l-0.34,3.7l3.61,0.82L8.6,22.5l3.4,-1.47l3.4,1.46l1.89,-3.19l3.61,-0.82l-0.34,-3.69L23,12zM9.38,16.01L7,13.61c-0.39,-0.39 -0.39,-1.02 0,-1.41l0.07,-0.07c0.39,-0.39 1.03,-0.39 1.42,0l1.61,1.62l5.15,-5.16c0.39,-0.39 1.03,-0.39 1.42,0l0.07,0.07c0.39,0.39 0.39,1.02 0,1.41l-5.92,5.94C10.41,16.4 9.78,16.4 9.38,16.01z" />
</vector>
Loading

0 comments on commit 1d15d51

Please sign in to comment.