PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/QingTingFanBianYi/src/fm/qingting/qtradio/im/ImBlackList.java

https://gitlab.com/qt-prometheus/qt-prometheus
Java | 155 lines | 140 code | 11 blank | 4 comment | 40 complexity | a889281663c535557d53a2fd5f247e2d MD5 | raw file
  1. package fm.qingting.qtradio.im;
  2. import android.content.Context;
  3. import android.content.SharedPreferences;
  4. import android.content.SharedPreferences.Editor;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import fm.qingting.framework.controller.ViewController;
  9. import fm.qingting.qtradio.controller.ControllerManager;
  10. import fm.qingting.qtradio.im.message.IMMessage;
  11. import fm.qingting.qtradio.room.SnsInfo;
  12. import fm.qingting.qtradio.room.UserInfo;
  13. import java.util.ArrayList;
  14. import java.util.List;
  15. public class ImBlackList
  16. {
  17. private static final String ID = "imblacklist";
  18. private static final String QUARYID = "imlist";
  19. private static List<BlackListItem> sBlackList;
  20. public static void addToBlackList(Context paramContext, IMMessage paramIMMessage)
  21. {
  22. if (sBlackList == null)
  23. {
  24. sBlackList = getBlackList(paramContext);
  25. if (sBlackList == null)
  26. sBlackList = new ArrayList();
  27. }
  28. if (inBlackList(paramContext, paramIMMessage.mFromID))
  29. return;
  30. BlackListItem localBlackListItem = new BlackListItem();
  31. localBlackListItem.name = paramIMMessage.mFromName;
  32. localBlackListItem.id = paramIMMessage.mFromID;
  33. localBlackListItem.avatar = BaseUserInfoPool.getAvatar(paramIMMessage.mFromID);
  34. sBlackList.add(0, localBlackListItem);
  35. saveBlackList(paramContext);
  36. }
  37. public static void addToBlackList(Context paramContext, UserInfo paramUserInfo)
  38. {
  39. if (sBlackList == null)
  40. {
  41. sBlackList = getBlackList(paramContext);
  42. if (sBlackList == null)
  43. sBlackList = new ArrayList();
  44. }
  45. if (inBlackList(paramContext, paramUserInfo.userKey))
  46. return;
  47. BlackListItem localBlackListItem = new BlackListItem();
  48. localBlackListItem.name = paramUserInfo.snsInfo.sns_name;
  49. localBlackListItem.avatar = paramUserInfo.snsInfo.sns_avatar;
  50. localBlackListItem.id = paramUserInfo.userKey;
  51. sBlackList.add(0, localBlackListItem);
  52. saveBlackList(paramContext);
  53. }
  54. public static List<BlackListItem> getBlackList(Context paramContext)
  55. {
  56. int i = 0;
  57. if (sBlackList != null)
  58. return sBlackList;
  59. sBlackList = new ArrayList();
  60. paramContext = paramContext.getSharedPreferences("imblacklist", 0).getString("imlist", "");
  61. if ((paramContext == null) || (paramContext.length() == 0))
  62. return null;
  63. paramContext = (JSONArray)JSONArray.parse(paramContext);
  64. if (paramContext != null)
  65. while (i < paramContext.size())
  66. {
  67. JSONObject localJSONObject = paramContext.getJSONObject(i);
  68. BlackListItem localBlackListItem = new BlackListItem();
  69. localBlackListItem.name = localJSONObject.getString("name");
  70. localBlackListItem.avatar = localJSONObject.getString("avatar");
  71. localBlackListItem.id = localJSONObject.getString("id");
  72. sBlackList.add(localBlackListItem);
  73. i += 1;
  74. }
  75. return sBlackList;
  76. }
  77. public static int getBlackListCnt(Context paramContext)
  78. {
  79. if (sBlackList == null)
  80. {
  81. sBlackList = getBlackList(paramContext);
  82. if (sBlackList == null)
  83. sBlackList = new ArrayList();
  84. }
  85. return sBlackList.size();
  86. }
  87. public static boolean inBlackList(Context paramContext, String paramString)
  88. {
  89. if (paramString == null);
  90. while (true)
  91. {
  92. return false;
  93. if (sBlackList == null)
  94. {
  95. sBlackList = getBlackList(paramContext);
  96. if (sBlackList == null)
  97. sBlackList = new ArrayList();
  98. }
  99. int i = 0;
  100. while (i < sBlackList.size())
  101. {
  102. if (((BlackListItem)sBlackList.get(i)).id.equalsIgnoreCase(paramString))
  103. return true;
  104. i += 1;
  105. }
  106. }
  107. }
  108. private static void refreshViewIfNeed()
  109. {
  110. ViewController localViewController = ControllerManager.getInstance().getLastViewController();
  111. if (localViewController.controllerName.equalsIgnoreCase("blockedmembers"))
  112. localViewController.config("resetData", null);
  113. }
  114. public static void removeFromBlackList(Context paramContext, BlackListItem paramBlackListItem)
  115. {
  116. if (!inBlackList(paramContext, paramBlackListItem.id))
  117. return;
  118. sBlackList.remove(paramBlackListItem);
  119. saveBlackList(paramContext);
  120. refreshViewIfNeed();
  121. }
  122. public static void saveBlackList(Context paramContext)
  123. {
  124. paramContext = paramContext.getSharedPreferences("imblacklist", 0).edit();
  125. if ((sBlackList == null) || (sBlackList.size() == 0))
  126. {
  127. paramContext.putString("imlist", "");
  128. paramContext.commit();
  129. }
  130. String str;
  131. do
  132. {
  133. return;
  134. str = JSON.toJSONString(sBlackList);
  135. }
  136. while (str == null);
  137. paramContext.putString("imlist", str);
  138. paramContext.commit();
  139. }
  140. }
  141. /* Location: C:\Users\User\dex2jar-2.0\dex\qting\classes-dex2jar.jar
  142. * Qualified Name: fm.qingting.qtradio.im.ImBlackList
  143. * JD-Core Version: 0.6.2
  144. */