Search in sources :

Example 1 with DynamicNotification

use of com.genonbeta.TrebleShot.util.DynamicNotification in project TrebleShot by genonbeta.

the class TransactionActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data != null) {
        if (resultCode == Activity.RESULT_OK) {
            switch(requestCode) {
                case REQUEST_CHOOSE_FOLDER:
                    if (data.hasExtra(FilePickerActivity.EXTRA_CHOSEN_PATH)) {
                        final Uri selectedPath = data.getParcelableExtra(FilePickerActivity.EXTRA_CHOSEN_PATH);
                        if (selectedPath.toString().equals(mGroup.savePath)) {
                            createSnackbar(R.string.mesg_pathSameError).show();
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(TransactionActivity.this);
                            builder.setTitle(R.string.ques_checkOldFiles);
                            builder.setMessage(R.string.text_checkOldFiles);
                            builder.setNeutralButton(R.string.butn_cancel, null);
                            builder.setNegativeButton(R.string.butn_reject, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    updateSavePath(selectedPath.toString());
                                }
                            });
                            builder.setPositiveButton(R.string.butn_accept, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    WorkerService.run(TransactionActivity.this, new WorkerService.NotifiableRunningTask(TAG, JOB_FILE_FIXICATION) {

                                        @Override
                                        public void onUpdateNotification(DynamicNotification dynamicNotification, UpdateType updateType) {
                                            switch(updateType) {
                                                case Started:
                                                    dynamicNotification.setSmallIcon(R.drawable.ic_compare_arrows_white_24dp).setContentText(getString(R.string.mesg_organizingFiles));
                                                    break;
                                                case Done:
                                                    dynamicNotification.setContentText(getString(R.string.text_movedCacheFiles));
                                                    break;
                                            }
                                        }

                                        @Override
                                        public void onRun() {
                                            ArrayList<TransactionObject> checkList = mDatabase.castQuery(new SQLQuery.Select(AccessDatabase.TABLE_TRANSFER).setWhere(AccessDatabase.FIELD_TRANSFER_GROUPID + "=? AND " + AccessDatabase.FIELD_TRANSFER_TYPE + "=? AND " + AccessDatabase.FIELD_TRANSFER_FLAG + " != ?", String.valueOf(mGroup.groupId), TransactionObject.Type.INCOMING.toString(), TransactionObject.Flag.PENDING.toString()), TransactionObject.class);
                                            TransactionObject.Group pseudoGroup = new TransactionObject.Group(mGroup.groupId);
                                            try {
                                                // Illustrate new change to build the structure accordingly
                                                mDatabase.reconstruct(pseudoGroup);
                                                pseudoGroup.savePath = selectedPath.toString();
                                                for (TransactionObject transactionObject : checkList) {
                                                    if (getInterrupter().interrupted())
                                                        break;
                                                    try {
                                                        DocumentFile file = FileUtils.getIncomingPseudoFile(getApplicationContext(), transactionObject, mGroup, false);
                                                        DocumentFile pseudoFile = FileUtils.getIncomingPseudoFile(getApplicationContext(), transactionObject, pseudoGroup, true);
                                                        if (file.canRead())
                                                            FileUtils.move(TransactionActivity.this, file, pseudoFile, getInterrupter());
                                                        file.delete();
                                                    } catch (IOException e) {
                                                        e.printStackTrace();
                                                    }
                                                }
                                                updateSavePath(selectedPath.toString());
                                            } catch (Exception e) {
                                                e.printStackTrace();
                                            }
                                        }
                                    });
                                }
                            });
                            builder.show();
                        }
                    }
                    break;
            }
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DocumentFile(com.genonbeta.TrebleShot.io.DocumentFile) DialogInterface(android.content.DialogInterface) DynamicNotification(com.genonbeta.TrebleShot.util.DynamicNotification) IOException(java.io.IOException) Uri(android.net.Uri) IOException(java.io.IOException) TransactionObject(com.genonbeta.TrebleShot.object.TransactionObject)

Aggregations

DialogInterface (android.content.DialogInterface)1 Uri (android.net.Uri)1 AlertDialog (android.support.v7.app.AlertDialog)1 DocumentFile (com.genonbeta.TrebleShot.io.DocumentFile)1 TransactionObject (com.genonbeta.TrebleShot.object.TransactionObject)1 DynamicNotification (com.genonbeta.TrebleShot.util.DynamicNotification)1 IOException (java.io.IOException)1