Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -50,7 +51,10 @@
import com.dimowner.audiorecorder.util.RippleUtils;

import java.io.File;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -82,6 +86,7 @@ public class SettingsActivity extends Activity implements SettingsContract.View,
private SettingView bitrateSetting;
private SettingView channelsSetting;
private Button btnReset;
private TextView btnDeleteOldRecordings;

private SettingsContract.UserActionsListener presenter;
private ColorMap colorMap;
Expand Down Expand Up @@ -130,6 +135,8 @@ protected void onCreate(Bundle savedInstanceState) {
btnView.setOnClickListener(this);
btnReset = findViewById(R.id.btnReset);
btnReset.setOnClickListener(this);
btnDeleteOldRecordings = findViewById(R.id.btnDeleteOldRecordings);
btnDeleteOldRecordings.setOnClickListener(this);
txtSizePerMin = findViewById(R.id.txt_size_per_min);
txtInformation = findViewById(R.id.txt_information);
txtLocation = findViewById(R.id.txt_records_location);
Expand Down Expand Up @@ -345,6 +352,8 @@ public void onClick(View v) {
} else if (id == R.id.btnReset) {
presenter.resetSettings();
presenter.loadSettings();
} else if (id == R.id.btnDeleteOldRecordings) {
showDeleteOldRecordingsPicker();
} else if (id == R.id.btnRequest) {
requestFeature();
}
Expand Down Expand Up @@ -384,6 +393,39 @@ private void requestFeature() {
}
}

private void showDeleteOldRecordingsPicker() {
final Calendar initial = Calendar.getInstance();
initial.add(Calendar.MONTH, -3);
final DatePickerDialog picker = new DatePickerDialog(
this,
(view, year, month, dayOfMonth) -> {
final Calendar cutoff = Calendar.getInstance();
cutoff.set(year, month, dayOfMonth, 0, 0, 0);
cutoff.set(Calendar.MILLISECOND, 0);
confirmDeleteOldRecordings(cutoff.getTimeInMillis());
},
initial.get(Calendar.YEAR),
initial.get(Calendar.MONTH),
initial.get(Calendar.DAY_OF_MONTH)
);
picker.getDatePicker().setMaxDate(System.currentTimeMillis());
picker.setTitle(R.string.delete_old_recordings_picker_title);
picker.show();
}

private void confirmDeleteOldRecordings(final long cutoffMillis) {
final String formatted = DateFormat.getDateInstance(DateFormat.MEDIUM)
.format(new Date(cutoffMillis));
final String message = getString(R.string.delete_old_recordings_confirm, formatted);
AndroidUtils.showDialogYesNo(
this,
R.drawable.ic_delete_forever,
getString(R.string.delete_old_recordings),
message,
v -> presenter.deleteRecordsOlderThan(cutoffMillis)
);
}

private Intent rateIntentForUrl(String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("%s?id=%s", url, getApplicationContext().getPackageName())));
int flags = Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
Expand Down Expand Up @@ -465,6 +507,17 @@ public void showFailDeleteAllRecords() {
Toast.makeText(getApplicationContext(), R.string.failed_to_delete_all_records, Toast.LENGTH_LONG).show();
}

@Override
public void showOldRecordsMovedToTrash(int count) {
final String msg = getResources().getQuantityString(R.plurals.old_records_moved_to_trash, count, count);
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}

@Override
public void showNoOldRecordsFound() {
Toast.makeText(getApplicationContext(), R.string.no_old_records_found, Toast.LENGTH_LONG).show();
}

@Override
public void showTotalRecordsDuration(String duration) {
txtTotalDuration.setText(getResources().getString(R.string.total_duration, duration));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ interface View extends Contract.View {

void showFailDeleteAllRecords();

void showOldRecordsMovedToTrash(int count);

void showNoOldRecordsFound();

void showTotalRecordsDuration(String duration);
void showRecordsCount(int count);
void showAvailableSpace(String space);
Expand Down Expand Up @@ -98,6 +102,8 @@ public interface UserActionsListener extends Contract.UserActionsListener<Settin

void deleteAllRecords();

void deleteRecordsOlderThan(long cutoffMillis);

void resetSettings();

void onRecordsLocationClick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,34 @@ public void setSettingRecordingFormat(String formatKey) {
updateAvailableSpace();
}

@Override
public void deleteRecordsOlderThan(final long cutoffMillis) {
recordingsTasks.postRunnable(() -> {
final List<Record> all = localRepository.getAllRecords();
int moved = 0;
for (int i = 0; i < all.size(); i++) {
final Record record = all.get(i);
if (record == null) continue;
final long stamp = record.getAdded() > 0 ? record.getAdded() : record.getCreated();
if (stamp > 0 && stamp < cutoffMillis) {
if (localRepository.deleteRecord(record.getId())) {
moved++;
}
}
}
final int total = moved;
AndroidUtils.runOnUIThread(() -> {
if (view != null) {
if (total == 0) {
view.showNoOldRecordsFound();
} else {
view.showOldRecordsMovedToTrash(total);
}
}
});
});
}

@Override
public void deleteAllRecords() {
recordingsTasks.postRunnable(() -> {
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,21 @@
android:drawablePadding="@dimen/spacing_normal"
/>

<TextView
android:id="@+id/btnDeleteOldRecordings"
style="@style/Text.NormalLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/delete_old_recordings"
android:drawableStart="@drawable/ic_delete_forever"
android:background="?android:selectableItemBackground"
android:paddingStart="@dimen/spacing_normal"
android:paddingEnd="@dimen/spacing_normal"
android:paddingTop="@dimen/spacing_medium"
android:paddingBottom="@dimen/spacing_medium"
android:drawablePadding="@dimen/spacing_normal"
/>

<TextView
android:id="@+id/txt_records_count"
android:layout_width="match_parent"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
<item quantity="one">Move to trash %d selected record?</item>
<item quantity="other">Move to trash %d selected records?</item>
</plurals>
<plurals name="old_records_moved_to_trash">
<item quantity="one">Moved %d record to Trash</item>
<item quantity="other">Moved %d records to Trash</item>
</plurals>
<string name="delete_old_recordings">Delete old recordings…</string>
<string name="delete_old_recordings_picker_title">Delete recordings older than:</string>
<string name="delete_old_recordings_confirm">Move all recordings older than %1$s to Trash?</string>
<string name="no_old_records_found">No recordings older than that date were found</string>
<plurals name="download_selected_records">
<item quantity="one">Copy %d selected record to the \'Downloads\' directory?</item>
<item quantity="other">Copy %d selected records to the \'Downloads\' directory?</item>
Expand Down