Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ShowThanksCount bug fixed; changed Settings and HideThreads(doesn't w…
…ork yet); version bumped; changed build tools
- Loading branch information
1 parent
915723e
commit af1709a
Showing
7 changed files
with
128 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package de.randombyte.xpit; | ||
|
||
import android.content.SharedPreferences; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import de.randombyte.xpit.hooks.HideThreads; | ||
|
||
/** | ||
* Helper class for managing the settings. | ||
*/ | ||
public class Settings { | ||
|
||
public static SharedPreferences TARGET_PREFS; | ||
|
||
public static String[] getHiddenThreadsString() { | ||
Set<String> idsString = TARGET_PREFS | ||
.getStringSet(HideThreads.HIDDEN_THREADS_PREF_KEY, new HashSet<String>()); | ||
return idsString.toArray(new String[idsString.size()]); | ||
} | ||
|
||
/** | ||
* Returns the threads that are marked by the user as hidden from the SharedPreferences. | ||
* @return Returns a map of id and last known title of the threads. | ||
*/ | ||
public static Map<Integer, String> getHiddenThreads() { | ||
String[] threadStrings = getHiddenThreadsString(); | ||
Map<Integer, String> threads = new HashMap<>(threadStrings.length); | ||
for (String threadString : threadStrings) { | ||
String[] pair = threadString.split(";", 2); //Ignore ";"s in title after first ";" | ||
threads.put(Integer.valueOf(pair[0]), pair[1]); | ||
} | ||
return threads; | ||
} | ||
|
||
public static void setHiddenThreads(Map<Integer, String> threads) { | ||
Set<String> threadsString = new HashSet<>(threads.size()); | ||
for (Map.Entry<Integer, String> thread : threads.entrySet()) { | ||
threadsString.add(thread.getKey() + ";" + thread.getValue()); //id;title | ||
} | ||
TARGET_PREFS.edit().putStringSet(HideThreads.HIDDEN_THREADS_PREF_KEY, threadsString).apply(); | ||
} | ||
|
||
/** | ||
* Adds a thread as hidden. | ||
* @param id The thread id | ||
* @param title The title of the thread; for user | ||
* @return True if the id already was mapped. | ||
*/ | ||
public static boolean addHiddenThread(int id, String title) { | ||
Map<Integer, String> hiddenThreads = getHiddenThreads(); | ||
boolean modified = hiddenThreads.put(id, title) != null; | ||
setHiddenThreads(hiddenThreads); | ||
return modified; | ||
} | ||
} |
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
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