Fixes a bug with issue #210

This commit is contained in:
stom79 2018-01-05 09:46:59 +01:00
parent a790066f07
commit dadae74991
4 changed files with 70 additions and 14 deletions

View File

@ -596,6 +596,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
final boolean isOwner = status.getAccount().getId().equals(userId);
popup.getMenuInflater()
.inflate(R.menu.option_toot, popup.getMenu());
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
if( status.getVisibility().equals("private") || status.getVisibility().equals("direct")){
popup.getMenu().findItem(R.id.action_mention).setVisible(false);
}

View File

@ -133,6 +133,25 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
private final int DISPLAYED_STATUS = 1;
private List<Status> pins;
private int conversationPosition;
private List<String> timedMute;
public StatusListAdapter(Context context, List<String> timedMute, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
super();
this.context = context;
this.statuses = statuses;
this.isOnWifi = isOnWifi;
this.behaviorWithAttachments = behaviorWithAttachments;
layoutInflater = LayoutInflater.from(this.context);
statusListAdapter = this;
this.type = type;
this.targetedId = targetedId;
this.translator = translator;
pins = new ArrayList<>();
this.timedMute = timedMute;
}
public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List<Status> statuses){
super();
@ -162,6 +181,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
pins = new ArrayList<>();
}
public void updateMuted(List<String> timedMute){
this.timedMute = timedMute;
}
@Override
public long getItemId(int position) {
return position;
@ -334,14 +357,15 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
else if (status.getIn_reply_to_id() != null && !status.getIn_reply_to_id().equals("null") && !sharedpreferences.getBoolean(Helper.SET_SHOW_REPLIES, true)) {
return HIDDEN_STATUS;
}else {
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Account account = new AccountDAO(context, db).getAccountByID(userId);
List<String> mutedAccount = new TempMuteDAO(context, db).getAllTimeMuted(account);
if( mutedAccount != null && mutedAccount.contains(status.getAccount().getId()))
return HIDDEN_STATUS;
else
if( timedMute != null && timedMute.size() > 0) {
if (timedMute.contains(status.getAccount().getId()))
return HIDDEN_STATUS;
else
return DISPLAYED_STATUS;
}else {
return DISPLAYED_STATUS;
}
}
}else {
if( context instanceof ShowAccountActivity){
@ -367,7 +391,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, @SuppressLint("RecyclerView") final int position) {
public void onBindViewHolder(final RecyclerView.ViewHolder viewHolder, int position) {
if( viewHolder.getItemViewType() == DISPLAYED_STATUS){
final ViewHolder holder = (ViewHolder) viewHolder;
@ -1123,10 +1147,14 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
popup.getMenu().findItem(R.id.action_block).setVisible(false);
popup.getMenu().findItem(R.id.action_mute).setVisible(false);
popup.getMenu().findItem(R.id.action_report).setVisible(false);
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_owner_confirm);
}else {
popup.getMenu().findItem(R.id.action_remove).setVisible(false);
stringArrayConf = context.getResources().getStringArray(R.array.more_action_confirm);
if( type != RetrieveFeedsAsyncTask.Type.HOME){
popup.getMenu().findItem(R.id.action_timed_mute).setVisible(false);
}
}
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
@ -1218,6 +1246,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Account account = new AccountDAO(context, db).getAccountByID(userId);
new TempMuteDAO(context, db).insert(account, targeted_id, new Date(time));
if( timedMute != null && !timedMute.contains(account.getId()))
timedMute.add(targeted_id);
else if (timedMute == null){
timedMute = new ArrayList<>();
timedMute.add(targeted_id);
}
Toast.makeText(context,context.getString(R.string.timed_mute_date,status.getAccount().getAcct(),Helper.dateToString(context, date_mute)), Toast.LENGTH_LONG).show();
alertDialog.dismiss();
notifyDataSetChanged();
@ -1591,6 +1625,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
private void notifyStatusChanged(Status status){
for (int i = 0; i < statusListAdapter.getItemCount(); i++) {
//noinspection ConstantConditions
if (statusListAdapter.getItemAt(i) != null && statusListAdapter.getItemAt(i).getId().equals(status.getId())) {
try {
statusListAdapter.notifyItemChanged(i);
@ -1606,7 +1641,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
if( !fromTranslation) {
if (!status.isEmojiFound()) {
for (int i = 0; i < statusListAdapter.getItemCount(); i++) {
//noinspection ConstantConditions
if (statusListAdapter.getItemAt(i) != null && statusListAdapter.getItemAt(i).getId().equals(status.getId())) {
//noinspection ConstantConditions
statusListAdapter.getItemAt(i).setEmojiFound(true);
try {
statusListAdapter.notifyItemChanged(i);
@ -1617,7 +1654,9 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}else {
if (!status.isEmojiTranslateFound()) {
for (int i = 0; i < statusListAdapter.getItemCount(); i++) {
//noinspection ConstantConditions
if (statusListAdapter.getItemAt(i) != null && statusListAdapter.getItemAt(i).getId().equals(status.getId())) {
//noinspection ConstantConditions
statusListAdapter.getItemAt(i).setEmojiTranslateFound(true);
try {
statusListAdapter.notifyItemChanged(i);

View File

@ -39,6 +39,7 @@ import fr.gouv.etalab.mastodon.activities.BaseMainActivity;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingFeedsAsyncTask;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingFeedsInterface;
@ -47,6 +48,7 @@ import fr.gouv.etalab.mastodon.services.StreamingLocalTimelineService;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO;
@ -116,11 +118,22 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
textviewNoAction = rootView.findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
if( type == RetrieveFeedsAsyncTask.Type.HOME) {
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(context, db).getAccountByID(userId);
List<String> mutedAccount = new TempMuteDAO(context, db).getAllTimeMuted(account);
statusListAdapter = new StatusListAdapter(context,mutedAccount, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
}else{
statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses);
}
lv_status.setAdapter(statusListAdapter);
mLayoutManager = new LinearLayoutManager(context);
lv_status.setLayoutManager(mLayoutManager);
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
lastReadStatus = sharedpreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId + instance, null);
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, context!=null?Helper.getLiveInstance(context):null);
@ -442,6 +455,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
//Cleans old timed mute accounts
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new TempMuteDAO(context, db).removeOld();
Account account = new AccountDAO(context, db).getAccountByID(userId);
List<String> mutedAccount = new TempMuteDAO(context, db).getAllTimeMuted(account);
statusListAdapter.updateMuted(mutedAccount);
}
}

View File

@ -77,7 +77,7 @@ public class TempMuteDAO {
* Remove mute by its id
*/
public void removeOld(){
db.delete(Sqlite.TABLE_TEMP_MUTE, Sqlite.COL_DATE_END + " < date('now')", null);
db.delete(Sqlite.TABLE_TEMP_MUTE, Sqlite.COL_DATE_END + " < \"" + Helper.dateToString(context, new Date())+ "\"", null);
}
//------- GETTERS -------
@ -88,7 +88,7 @@ public class TempMuteDAO {
*/
public List<String> getAllTimeMuted(Account account){
try {
Cursor c = db.query(Sqlite.TABLE_TEMP_MUTE, null, Sqlite.COL_DATE_END + " >= date('now') AND " + Sqlite.COL_ACCT + " = \"" + account.getAcct()+ "\" AND " + Sqlite.COL_INSTANCE + " = \"" + account.getInstance()+ "\"", null, null, null, null, null);
Cursor c = db.query(Sqlite.TABLE_TEMP_MUTE, null, Sqlite.COL_DATE_END + " >= \"" + Helper.dateToString(context, new Date())+ "\" AND " + Sqlite.COL_ACCT + " = \"" + account.getAcct()+ "\" AND " + Sqlite.COL_INSTANCE + " = \"" + account.getInstance()+ "\"", null, null, null, null, null);
return cursorToTimeMute(c);
} catch (Exception e) {
return null;
@ -102,7 +102,7 @@ public class TempMuteDAO {
*/
public boolean isTempMuted(Account account, String targeted_id){
try {
Cursor c = db.query(Sqlite.TABLE_TEMP_MUTE, null, Sqlite.COL_TARGETED_USER_ID + " = \"" + targeted_id + "\" AND " + Sqlite.COL_ACCT + " = \"" + account.getAcct()+ "\" AND " + Sqlite.COL_INSTANCE + " = \"" + account.getInstance()+ "\"", null, null, null, null, null);
Cursor c = db.query(Sqlite.TABLE_TEMP_MUTE, null, Sqlite.COL_TARGETED_USER_ID + " = \"" + targeted_id + "\" AND " + Sqlite.COL_DATE_END + " >= \"" + Helper.dateToString(context, new Date())+ "\" AND " + Sqlite.COL_ACCT + " = \"" + account.getAcct()+ "\" AND " + Sqlite.COL_INSTANCE + " = \"" + account.getInstance()+ "\"", null, null, null, null, null);
return cursorToTimeMute(c) != null;
} catch (Exception e) {
return false;
@ -116,7 +116,7 @@ public class TempMuteDAO {
*/
public String getMuteDateByID(Account account, String targeted_id){
try {
Cursor c = db.query(Sqlite.TABLE_TEMP_MUTE, null, Sqlite.COL_TARGETED_USER_ID + " = \"" + targeted_id + "\" AND " + Sqlite.COL_ACCT + " = \"" + account.getAcct()+ "\" AND " + Sqlite.COL_INSTANCE + " = \"" + account.getInstance()+ "\"", null, null, null, Sqlite.COL_DATE_END + " DESC", "1");
Cursor c = db.query(Sqlite.TABLE_TEMP_MUTE, null, Sqlite.COL_TARGETED_USER_ID + " = \"" + targeted_id + "\" AND " + Sqlite.COL_DATE_END + " >= \"" + Helper.dateToString(context, new Date())+ "\" AND " + Sqlite.COL_ACCT + " = \"" + account.getAcct()+ "\" AND " + Sqlite.COL_INSTANCE + " = \"" + account.getInstance()+ "\"", null, null, null, Sqlite.COL_DATE_END + " DESC", "1");
return cursorToDate(c);
} catch (Exception e) {
e.printStackTrace();