This repository has been archived by the owner on Jan 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from itning/dev_1.3
1.3 Release
- Loading branch information
Showing
31 changed files
with
1,082 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/java/top/itning/getupearly/config/Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package top.itning.getupearly.config; | ||
|
||
import androidx.annotation.CheckResult; | ||
import androidx.annotation.NonNull; | ||
|
||
import java.util.Map; | ||
|
||
import top.itning.getupearly.constant.Api; | ||
import top.itning.getupearly.constant.ViewItem; | ||
|
||
/** | ||
* 用户配置 | ||
* | ||
* @author itning | ||
* @date 2020/8/10 20:04 | ||
*/ | ||
public interface Config<T> { | ||
/** | ||
* 获取配置信息 | ||
* | ||
* @return 映射 | ||
*/ | ||
@NonNull | ||
@CheckResult | ||
Map<ViewItem<T>, Boolean> getConfig(); | ||
|
||
/** | ||
* 保存配置信息 | ||
* | ||
* @param api API | ||
* @param isShow 是否显示 | ||
* @param order 顺序 | ||
*/ | ||
void saveConfig(@NonNull Api api, boolean isShow, int order); | ||
} |
61 changes: 61 additions & 0 deletions
61
app/src/main/java/top/itning/getupearly/config/SharedPreferencesConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package top.itning.getupearly.config; | ||
|
||
import android.content.SharedPreferences; | ||
|
||
import androidx.annotation.CheckResult; | ||
import androidx.annotation.NonNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import top.itning.getupearly.constant.Api; | ||
import top.itning.getupearly.constant.ApiBundle; | ||
import top.itning.getupearly.constant.ViewItem; | ||
|
||
/** | ||
* SharedPreferences实现配置 | ||
* | ||
* @author itning | ||
* @date 2020/8/10 20:07 | ||
*/ | ||
public class SharedPreferencesConfig implements Config<Api> { | ||
|
||
private static final String ORDER_PREFIX = "ORDER_"; | ||
|
||
private static final String IS_SHOW_PREFIX = "SHOW_"; | ||
|
||
@NonNull | ||
private final SharedPreferences sharedPref; | ||
|
||
public SharedPreferencesConfig(@NonNull SharedPreferences sharedPref) { | ||
this.sharedPref = sharedPref; | ||
} | ||
|
||
@Override | ||
@NonNull | ||
@CheckResult | ||
public Map<ViewItem<Api>, Boolean> getConfig() { | ||
Map<ViewItem<Api>, Boolean> map = new HashMap<>(); | ||
for (Api api : Api.values()) { | ||
map.put(new ApiBundle(api, sharedPref.getInt(getOrderKey(api.name()), Integer.MAX_VALUE)), sharedPref.getBoolean(getIsShowKey(api.name()), true)); | ||
} | ||
return map; | ||
} | ||
|
||
@Override | ||
public void saveConfig(@NonNull Api api, boolean isShow, int order) { | ||
sharedPref | ||
.edit() | ||
.putBoolean(getIsShowKey(api.name()), isShow) | ||
.putInt(getOrderKey(api.name()), order) | ||
.apply(); | ||
} | ||
|
||
public static String getOrderKey(String value) { | ||
return ORDER_PREFIX + value; | ||
} | ||
|
||
public static String getIsShowKey(String value) { | ||
return IS_SHOW_PREFIX + value; | ||
} | ||
} |
Oops, something went wrong.