Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,9 @@ public boolean onLongClick (View v) {
context.currentTdlib().ui().addAccount(context, true, true);
}
});
} else if (itemId == R.id.btn_calls) {
clearRecentCalls();
return true;
}
return false;
}
Expand All @@ -814,6 +817,27 @@ public boolean onLongClick (View v) {
return false;
}

public void clearRecentCalls () {
showSettings(new SettingsWrapBuilder(R.id.btn_delete)
.setHeaderItem(new ListItem(ListItem.TYPE_INFO, R.id.text_title, 0, R.string.AreYouSureClearCalls, false))
.setRawItems(
new ListItem[]{
new ListItem(ListItem.TYPE_CHECKBOX_OPTION, R.id.btn_deleteAll, 0, R.string.DeleteForEveryone, false)
})
.setIntDelegate((id, result) -> {
if (id == R.id.btn_delete) {
context.currentTdlib().clearCallsHistory(result.get(R.id.btn_deleteAll) != 0, success -> {
if (success) {
UI.showToast(R.string.Done, Toast.LENGTH_SHORT);
}
});
}
})
.setSaveStr(R.string.Delete)
.setSaveColorId(ColorId.textNegative)
);
}

@Override
public void onClick (View v) {
int viewId = v.getId();
Expand Down Expand Up @@ -1446,4 +1470,4 @@ public static DrawerHolder create (Context context, int viewType, View.OnClickLi
throw new IllegalArgumentException("viewType == " + viewType);
}
}*/
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/org/thunderdog/challegram/telegram/Tdlib.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import androidx.collection.LongSparseArray;
import androidx.collection.SparseArrayCompat;
import androidx.core.os.CancellationSignal;
import androidx.core.util.Consumer;
import androidx.core.util.Pair;

import com.google.android.gms.tasks.Task;
Expand Down Expand Up @@ -99,6 +100,7 @@
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
Expand Down Expand Up @@ -10804,6 +10806,23 @@ public boolean canEditSlowMode (long chatId) {
return false;
}

public void clearCallsHistory(boolean revoke, Consumer<Boolean> callback) {
var _TAG = "ClearCallsHistory";
client().send(new TdApi.DeleteAllCallMessages(revoke), object -> {
if (object instanceof TdApi.Ok) {
Log.d(_TAG, "Call history cleared successfully." + (revoke ? " All call messages have been revoked." : ""));
callback.accept(true);
} else if (object instanceof TdApi.Error) {
TdApi.Error error = (TdApi.Error) object;
Log.e(_TAG, String.format(Locale.US, "Error clearing call history: Code %d, Message: %s", error.code, error.message));
callback.accept(false);
} else {
Log.w(_TAG, "Unexpected response from TDLib: " + object);
callback.accept(false);
}
});
}

public boolean isBroadcastGroup (long chatId) {
TdApi.Supergroup supergroup = chatToSupergroup(chatId);
return supergroup != null && supergroup.isBroadcastGroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
Expand All @@ -33,6 +35,8 @@
import org.thunderdog.challegram.data.CallItem;
import org.thunderdog.challegram.data.CallSection;
import org.thunderdog.challegram.data.TGFoundChat;
import org.thunderdog.challegram.navigation.HeaderView;
import org.thunderdog.challegram.navigation.MoreDelegate;
import org.thunderdog.challegram.navigation.SettingsWrapBuilder;
import org.thunderdog.challegram.navigation.ViewController;
import org.thunderdog.challegram.telegram.DateChangeListener;
Expand All @@ -41,6 +45,7 @@
import org.thunderdog.challegram.telegram.TdlibOptionListener;
import org.thunderdog.challegram.theme.ColorId;
import org.thunderdog.challegram.tool.Screen;
import org.thunderdog.challegram.tool.UI;
import org.thunderdog.challegram.tool.Views;
import org.thunderdog.challegram.unsorted.Settings;
import org.thunderdog.challegram.util.StringList;
Expand All @@ -66,6 +71,7 @@ public class CallListController extends RecyclerViewController<Void> implements
View.OnClickListener,
Client.ResultHandler,
MessageListener,
MoreDelegate,
DateChangeListener,
View.OnLongClickListener,
BaseView.ActionListProvider, TdlibOptionListener {
Expand All @@ -83,6 +89,56 @@ public CharSequence getName () {
return Lang.getString(R.string.Calls);
}

@Override
protected int getMenuId () {
return messages != null && !messages.isEmpty() ? R.id.menu_btn_more : 0;
}

@Override
public void fillMenuItems (int id, HeaderView header, LinearLayout menu) {
if (id == R.id.menu_btn_more) {
header.addMoreButton(menu, this);
}
}

@Override
public void onMenuItemPressed (int id, View view) {
if (id == R.id.menu_btn_more) {
showMore(new int[] {R.id.btn_clear_recent_calls}, new String[] {Lang.getString(R.string.ClearRecentCalls)});
}
}

@Override
public void onMoreItemPressed (int id) {
if (id == R.id.btn_clear_recent_calls) {
showClearCallsConfirmationDialog();
}
}

public boolean hasRecentCalls() {
return messages != null && !messages.isEmpty();
}

private void showClearCallsConfirmationDialog() {
showSettings(new SettingsWrapBuilder(R.id.btn_delete)
.setHeaderItem(new ListItem(ListItem.TYPE_INFO, R.id.text_title, 0, R.string.AreYouSureClearCalls, false))
.setRawItems(new ListItem[] {
new ListItem(ListItem.TYPE_CHECKBOX_OPTION, R.id.btn_deleteAll, 0, R.string.DeleteForEveryone, false)
})
.setIntDelegate((_id, result) -> {
if (_id == R.id.btn_delete) {
context.currentTdlib().clearCallsHistory(result.get(R.id.btn_deleteAll) != 0, success -> {
if (success) {
UI.showToast(R.string.Done, Toast.LENGTH_SHORT);
}
});
}
})
.setSaveStr(R.string.Delete)
.setSaveColorId(ColorId.textNegative)
);
}

private SettingsAdapter adapter;

@Override
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/org/thunderdog/challegram/ui/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1455,10 +1455,39 @@ public boolean onPagerItemLongClick (int index) {
TdApi.ChatList chatList = pagerChatLists.get(index);
showChatListOptions(chatList);
return true;
} else if (index == POSITION_CALLS) {
ViewController<?> controller = getCachedControllerForPosition(index);
if (controller instanceof CallListController) {
CallListController callListController = (CallListController) controller;
if (callListController.hasRecentCalls()) {
showClearCallsConfirmationDialog();
return true;
}
}
}
return false;
}

private void showClearCallsConfirmationDialog() {
showSettings(new SettingsWrapBuilder(R.id.btn_delete)
.setHeaderItem(new ListItem(ListItem.TYPE_INFO, R.id.text_title, 0, R.string.AreYouSureClearCalls, false))
.setRawItems(new ListItem[] {
new ListItem(ListItem.TYPE_CHECKBOX_OPTION, R.id.btn_deleteAll, 0, R.string.DeleteForEveryone, false)
})
.setIntDelegate((_id, result) -> {
if (_id == R.id.btn_delete) {
context.currentTdlib().clearCallsHistory(result.get(R.id.btn_deleteAll) != 0, success -> {
if (success) {
UI.showToast(R.string.Done, Toast.LENGTH_SHORT);
}
});
}
})
.setSaveStr(R.string.Delete)
.setSaveColorId(ColorId.textNegative)
);
}

private ChatsController newChatsController (TdApi.ChatList chatList, @Filter int filter) {
ChatsController chats = new ChatsController(this.context, tdlib).setParent(this);
ChatFilter chatFilter;
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1411,4 +1411,8 @@
<item type="id" name="btn_playback_speed_1_2" />
<item type="id" name="btn_playback_speed_1_5" />
<item type="id" name="btn_playback_speed_2_0" />

<item type="id" name="menu_clear_recent_calls" />
<item type="id" name="btn_clear_recent_calls" />

</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5609,4 +5609,6 @@
<string name="xBotUsers_one">%1$s monthly user</string>
<string name="xBotUsers_other">%1$s monthly users</string>

<string name="AreYouSureClearCalls">Do you want to delete all recent calls?</string>
<string name="ClearRecentCalls">Clear recent calls</string>
</resources>