Skip to content

Commit

Permalink
Merge branch 'feature/optional' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
VenomVendor committed Mar 9, 2016
2 parents 54d633e + bd63d29 commit 3b89061
Show file tree
Hide file tree
Showing 14 changed files with 341 additions and 169 deletions.
13 changes: 13 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ android {
versionName rootProject.ext.versionName
}

productFlavors {
froyo {
minSdkVersion 8
versionCode rootProject.ext.froyo
}
donut {
minSdkVersion 4
maxSdkVersion 7
targetSdkVersion 7
versionCode rootProject.ext.donut
}
}

signingConfigs {
release {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckedTextView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.venomvendor.sms.deduplicate.R;
import com.venomvendor.sms.deduplicate.data.FindDuplicates;
import com.venomvendor.sms.deduplicate.data.FindDuplicates.OnDuplicatesFoundListener;
import com.venomvendor.sms.deduplicate.service.DeleteSmsService;
import com.venomvendor.sms.deduplicate.util.Constants;
import com.venomvendor.sms.deduplicate.util.Utils;
Expand Down Expand Up @@ -72,6 +75,12 @@ public class Deduplication extends Activity implements View.OnClickListener {
private Button mCancel;
private Button mRevert;
private TextView mDeleted;
private TextView mRevertMessage;
private CheckedTextView mIgnoreTimestamp;
private LinearLayout mIgnoreMessage;
private RadioButton mKeepFirst;
private SharedPreferences mPref;

private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Expand All @@ -84,25 +93,27 @@ public void onReceive(Context context, Intent intent) {
mCancel.setText(android.R.string.cancel);
mDeDuplicate.setVisibility(View.VISIBLE);
mProgressBarHolder.setVisibility(View.GONE);
Toast toast = Toast.makeText(context, String.format(getString(R.string.deleted_messages),
deletedMessages, totalMessages), Toast.LENGTH_SHORT);

String format = getResources().getQuantityString(R.plurals.deleted_messages, totalMessages);
Toast toast = Toast.makeText(context, String.format(format, deletedMessages, totalMessages), Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
mDeleted.setText(String.format(getString(R.string.deleted_messages),
deletedMessages, totalMessages));

String format = getResources().getQuantityString(R.plurals.deleted_messages, totalMessages);

mDeleted.setText(String.format(format, deletedMessages, totalMessages));
mProgressBar.setMax(totalMessages);
mProgressBar.setProgress(deletedMessages);
}
};
private TextView mRevertMessage;
private SharedPreferences mPref;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_deduplication);

mPref = PreferenceManager.getDefaultSharedPreferences(this);

if (mPref.getBoolean(Constants.SHOW_EULA, true)) {
Expand All @@ -113,7 +124,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void showEula() {
AlertDialog.Builder builder = new AlertDialog.Builder(Deduplication.this)
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle(getString(R.string.app_name))
.setMessage(getString(R.string.eula))
.setCancelable(false)
Expand All @@ -125,6 +136,7 @@ public void onClick(DialogInterface dialog, int which) {
editor.putBoolean(Constants.SHOW_EULA, false);
editor.commit();
dialog.dismiss();
initViews();
}
})
.setNegativeButton(android.R.string.cancel,
Expand All @@ -137,21 +149,29 @@ public void onClick(DialogInterface dialog, int which) {
builder.create().show();
}

@TargetApi(Build.VERSION_CODES.KITKAT)
private void initViews() {
mDeDuplicate = (Button) findViewById(R.id.deduplicate);
Button mMoreApps = (Button) findViewById(R.id.more_apps);
mCancel = (Button) findViewById(R.id.cancel);
mRevert = (Button) findViewById(R.id.revert);
mDeleted = (TextView) findViewById(R.id.current_progress);
mRevertMessage = (TextView) findViewById(R.id.revert_message);
mProgressBarHolder = (LinearLayout) findViewById(R.id.progress_bar_holder);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
mIgnoreTimestamp = (CheckedTextView) findViewById(R.id.ignore_timestamp);
mIgnoreMessage = (LinearLayout) findViewById(R.id.ignore_timestamp_message);
mKeepFirst = (RadioButton) findViewById(R.id.keep_first);

initListeners();
}

@TargetApi(Build.VERSION_CODES.KITKAT)
private void initListeners() {
findViewById(R.id.more_apps).setOnClickListener(this);
mDeDuplicate.setOnClickListener(this);
mMoreApps.setOnClickListener(this);
mCancel.setOnClickListener(this);
mRevert.setOnClickListener(this);
mIgnoreTimestamp.setOnClickListener(this);

if (getIntent().getBooleanExtra(Constants.FROM_SERVICE, false)) {
doCancel();
}
Expand Down Expand Up @@ -255,7 +275,7 @@ private void deadLock() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Deduplication.this.finish();
finish();
}
}, null
);
Expand All @@ -269,24 +289,10 @@ protected void onNewIntent(Intent intent) {
}
}

@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.deduplicate:
deduplicate();
break;
case R.id.more_apps:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q=pub:VenomVendor"));
startActivity(intent);
break;
case R.id.cancel:
doCancel();
break;
case R.id.revert:
Utils.revertOldApp(getApplicationContext());
break;
}
private void showHideWarning() {
mKeepFirst.setChecked(true);
mIgnoreTimestamp.setChecked(!mIgnoreTimestamp.isChecked());
mIgnoreMessage.setVisibility(mIgnoreTimestamp.isChecked() ? View.VISIBLE : View.GONE);
}

private void doCancel() {
Expand All @@ -300,7 +306,7 @@ private void doCancel() {

private void cancelDeletion() {
if (mService == null) {
mService = new Intent(Deduplication.this, DeleteSmsService.class);
mService = new Intent(this, DeleteSmsService.class);
}
stopService(mService);
}
Expand All @@ -309,7 +315,8 @@ private void cancelDeletion() {
private void deduplicate() {
mProgressBar.setMax(0);
mProgressBar.setProgress(0);
mDeleted.setText(String.format(getString(R.string.deleted_messages), 0, 0));

mDeleted.setText(String.format(getResources().getQuantityString(R.plurals.deleted_messages, 0), 0, 0));
mProgressBarHolder.setVisibility(View.GONE);
if (!isValidMessageApp(this)) {
Intent setApp = new Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
Expand Down Expand Up @@ -341,20 +348,25 @@ public void onClick(DialogInterface dialog, int id) {
}

private void findDuplicates() {
FindDuplicates findDuplicates = new FindDuplicates(Deduplication.this);
findDuplicates.setOnDeleteDuplicatesListener(new FindDuplicates.OnDeleteDuplicatesListener() {
FindDuplicates findDuplicates = new FindDuplicates(this, mIgnoreTimestamp.isChecked(), mKeepFirst.isChecked());
findDuplicates.setOnDuplicatesFoundListener(new OnDuplicatesFoundListener() {
@Override
public void deleteDuplicates(ArrayList<String> duplicateIds) {
mDeDuplicate.setVisibility(View.GONE);
mProgressBarHolder.setVisibility(View.VISIBLE);
startDeleteService(duplicateIds);
public void duplicatesFound(ArrayList<String> duplicateIds) {
if (duplicateIds.isEmpty()) {
Toast.makeText(getApplicationContext(), R.string.no_duplicates, Toast.LENGTH_SHORT).show();
Utils.revertOldApp(getApplicationContext());
} else {
mDeDuplicate.setVisibility(View.GONE);
mProgressBarHolder.setVisibility(View.VISIBLE);
startDeleteService(duplicateIds);
}
}
});
findDuplicates.execute();
}

private void startDeleteService(ArrayList<String> duplicateIds) {
mService = new Intent(Deduplication.this, DeleteSmsService.class);
mService = new Intent(this, DeleteSmsService.class);
mService.putStringArrayListExtra(Constants.DUPLICATE_IDS, duplicateIds);
startService(mService);
}
Expand All @@ -365,11 +377,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == APP_CHANGE_REQUEST) {
if (resultCode == RESULT_OK || isValidMessageApp(this)) {
mRevert.setVisibility(View.VISIBLE);
mRevertMessage.setVisibility(View.VISIBLE);
mRevertMessage.setVisibility(View.GONE);
showWarning();
} else {
mRevert.setVisibility(View.GONE);
mRevertMessage.setVisibility(View.GONE);
mRevertMessage.setVisibility(View.VISIBLE);
showCustomDialog(getString(R.string.failed), getString(R.string.failure_message),
new DialogInterface.OnClickListener() {
@Override
Expand All @@ -388,6 +400,29 @@ public void onClick(DialogInterface dialog, int which) {

}

@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.deduplicate:
deduplicate();
break;
case R.id.more_apps:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("market://search?q=pub:VenomVendor"));
startActivity(intent);
break;
case R.id.cancel:
doCancel();
break;
case R.id.revert:
Utils.revertOldApp(getApplicationContext());
break;
case R.id.ignore_timestamp:
showHideWarning();
break;
}
}

@Override
protected void onPause() {
unregisterReceiver(mMessageReceiver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.AsyncTask;
import android.widget.Toast;

import com.venomvendor.sms.deduplicate.R;
import com.venomvendor.sms.deduplicate.util.Constants;
Expand All @@ -38,16 +37,23 @@ public class FindDuplicates extends AsyncTask<Void, Void, Boolean> {
private final ArrayList<String> mDuplicateIds = new ArrayList<String>();
private final List<Integer> mHashCodeCache = new ArrayList<Integer>();
private final Activity mContext;
private final boolean mChecked;
private final boolean mKeepFirst;
private ProgressDialog mProgressDialog;
private Cursor mCursor;
private int mIndex;
private OnDeleteDuplicatesListener mListener;
private OnDuplicatesFoundListener mListener;

public FindDuplicates(Activity activity) {
public FindDuplicates(Activity activity, boolean checked, boolean keepFirst) {
this.mContext = activity;
this.mChecked = checked;
this.mKeepFirst = keepFirst;
}

public void setOnDeleteDuplicatesListener(OnDeleteDuplicatesListener listener) {
public void setOnDuplicatesFoundListener(OnDuplicatesFoundListener listener) {
if (listener == null) {
throw new NullPointerException("Listener cannot be null.");
}
this.mListener = listener;
}

Expand All @@ -63,7 +69,8 @@ protected void onPreExecute() {

@Override
protected Boolean doInBackground(Void... params) {
mCursor = mContext.getContentResolver().query(Constants.CONTENT_URI, null, null, null, null);
String sortOrder = mChecked ? Constants.DATE + (mKeepFirst ? " ASC" : " DESC") : null;
mCursor = mContext.getContentResolver().query(Constants.CONTENT_URI, null, null, null, sortOrder);
if (mCursor != null) {
mProgressDialog.setMax(mCursor.getCount());
try {
Expand All @@ -87,9 +94,12 @@ protected Boolean doInBackground(Void... params) {
private void collectDuplicates() {
final String _id = Integer.toString(mCursor.getInt(0));
final List<String> uniqueData = new ArrayList<String>();

uniqueData.add(mCursor.getString(mCursor.getColumnIndex(Constants.ADDRESS)));
uniqueData.add(mCursor.getString(mCursor.getColumnIndex(Constants.DATE)));
uniqueData.add(mCursor.getString(mCursor.getColumnIndex(Constants.BODY)));
if (!mChecked) {
uniqueData.add(mCursor.getString(mCursor.getColumnIndex(Constants.DATE)));
}
int hashCode = uniqueData.hashCode();

if (mHashCodeCache.contains(hashCode)) {
Expand All @@ -115,41 +125,41 @@ protected void onPostExecute(Boolean result) {
}

private void showConfirmation() {

if (mDuplicateIds.isEmpty()) {
Toast.makeText(mContext, R.string.no_duplicates, Toast.LENGTH_SHORT).show();
return;
deleteDuplicates();
} else {
AlertDialog.Builder confirmationDialog = new AlertDialog.Builder(mContext);
confirmationDialog.setCancelable(false);
confirmationDialog.setMessage(mContext.getResources()
.getQuantityString(R.plurals.delete_duplicates, mDuplicateIds.size(), mDuplicateIds.size()));

confirmationDialog.setPositiveButton(mContext.getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
deleteDuplicates();
}
});
confirmationDialog.setNegativeButton(mContext.getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
confirmationDialog.show();
}

AlertDialog.Builder confirmationDialog = new AlertDialog.Builder(mContext);
confirmationDialog.setCancelable(false);
confirmationDialog.setMessage(String.format(mContext.getString(R.string.delete_duplicates), mDuplicateIds.size()));

confirmationDialog.setPositiveButton(mContext.getString(android.R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
deleteDuplicates();
}
});
confirmationDialog.setNegativeButton(mContext.getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
confirmationDialog.show();
}

private void deleteDuplicates() {
if (mListener != null) {
mListener.deleteDuplicates(mDuplicateIds);
if (mListener == null) {
throw new NullPointerException("OnDuplicatesFoundListener not implemented.");
}
mListener.duplicatesFound(mDuplicateIds);
mDuplicateIds.clear();
}

public interface OnDeleteDuplicatesListener {
void deleteDuplicates(ArrayList<String> duplicateIds);
public interface OnDuplicatesFoundListener {
void duplicatesFound(ArrayList<String> duplicateIds);
}

}
Loading

0 comments on commit 3b89061

Please sign in to comment.