-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1123 from meenbeese/rewrite-del-frag
Rewrite OnionServiceDeleteDialogFragment in Kotlin
- Loading branch information
Showing
2 changed files
with
43 additions
and
46 deletions.
There are no files selected for viewing
46 changes: 0 additions & 46 deletions
46
.../main/java/org/torproject/android/ui/v3onionservice/OnionServiceDeleteDialogFragment.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
...rc/main/java/org/torproject/android/ui/v3onionservice/OnionServiceDeleteDialogFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.torproject.android.ui.v3onionservice | ||
|
||
import android.app.Dialog | ||
import android.content.Context | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
|
||
import androidx.appcompat.app.AlertDialog | ||
import androidx.fragment.app.DialogFragment | ||
|
||
import org.torproject.android.R | ||
import org.torproject.android.core.DiskUtils.recursivelyDeleteDirectory | ||
import org.torproject.android.service.OrbotConstants | ||
|
||
import java.io.File | ||
|
||
class OnionServiceDeleteDialogFragment internal constructor(arguments: Bundle?) : DialogFragment() { | ||
init { | ||
setArguments(arguments) | ||
} | ||
|
||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
return AlertDialog.Builder(requireContext()) | ||
.setTitle(R.string.confirm_service_deletion) | ||
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int -> doDelete(arguments, requireContext()) } | ||
.setNegativeButton(android.R.string.cancel) { dialog: DialogInterface, _: Int -> dialog.cancel() } | ||
.create() | ||
} | ||
|
||
private fun doDelete(arguments: Bundle?, context: Context) { | ||
context.contentResolver.delete( | ||
OnionServiceContentProvider.CONTENT_URI, | ||
OnionServiceContentProvider.OnionService._ID + '=' + requireArguments().getInt( | ||
OnionServiceActivity.BUNDLE_KEY_ID | ||
), | ||
null | ||
) | ||
val base = context.filesDir.absolutePath + "/" + OrbotConstants.ONION_SERVICES_DIR | ||
val localPath = arguments?.getString(OnionServiceActivity.BUNDLE_KEY_PATH) | ||
localPath?.let { recursivelyDeleteDirectory(File(base, localPath)) } | ||
(requireActivity() as OnionServiceActivity).showBatteryOptimizationsMessageIfAppropriate() | ||
} | ||
} |